Showing posts with label SAS. Show all posts
Showing posts with label SAS. Show all posts

Sunday, June 28, 2020

SAS Programming Basic Questions

Following are the questions related to Base SAS.
  1. How many windows are displayed when a SAS session is started?
  2. How can I improve my knowledge about different SAS windows?
  3. What is enhanced editor window?
  4. How can I change the text color, size, font etc. of editor window?
  5. What is explorer window?
  6. What is log window?
  7. What do you mean by bug and debugging?
  8. How can I clear the contents of output, log or editor window?
  9. What is output window?
  10. How can I change the setting so that SAS displays the last output instead of first one?
  11. What is the object type for output window?
  12. What is displayed in RESULT window?
  13. There are certain terms or expression I use very often in codes. How can I create abbreviations for them?
  14. How can I record a keyboard macro?
  15. How can I convert selected text in editor window into comments?
  16. How can I create bookmark for a line?
  17. What are file shortcuts?
  18. How can I set the default output type? 
  19. Enhanced editor window has many shortcuts. How can I read / know them? 
  20. How can I place an icon at SAS tool bar for a command?
  21. How can I create objects of a catalog?
  22. Is it compulsory to specify data set name in data statement?
  23. Is it necessary to specify RUN statement at the end of DATA Step?
  24. What is INFILE statement? 
  25. What is INPUT statement?
  26. What is difference between input and infile statement?
  27. Write various options used in infile statement.
  28. What is FLOWOVER?
  29. What is MISSOVER?
  30. What is STOPOVER?
  31. What is RECFM=N option of infile statement?
  32. What is LENGTH=variable option of infile statement?
  33. What difference is between put and file statement?
  34. What is list input method?
  35. What is formatted input method?
  36. What is an informat?
  37. What is difference between list input and formatted input methods?
  38. What are various Pointer control features?
  39. What are Column pointer controls?
  40. Explain Line pointer control.
  41. Explain Line hold control.
  42. Explain Binary file indicator controls.
  43. Explain pattern searching feature.
  44. What is the meaning of $ symbol in input statement?
  45. What is the meaning of & symbol in input statement?
  46. When should I use list input method?
  47. Explain Record Directives.
  48. How can I test EOF condition?
  49. What are differences between SAS data step and IML?
  50. What is the role of LRECL=operand in FILE statement?
  51. Explain PUT statement.
  52. How is permanent data set created?
  53. What is library?
  54. Is it necessary to provide library reference in LIBNAME statement apart from folder path for physical location of the library folder?
  55. What is IML?
  56. What is difference between FILENAME and FILEPATH?
  57. Differentiate between CARDS, LOG and PRINT filenames?
  58. What are two major types of external files?
  59. How can I read a binary file?
  60. I have created a data set. How can I know about the descriptive information of this data set?
  61. How to write the SAS output in a text file?
  62. How to see the output in log window?
  63. Can we use label statement in PROC step?
  64. What is the use of PROC format?
  65. How can you view the built-in formats?
  66. What is the use of PUT _PAGE_?
  67. What is the use of PUT _ALL_?
  68. Suppose you have created a format folder XX. Now if you wish to see the format definitions of XX then what will you do?
  69. How does SAS search for formats?
  70. How can you create SAS data set from an excel file?
  71. How can you create an excel file from SAS data set?
  72. How can you activate command bar?
  73. What is RECALL command?
  74. What are the uses of VIEWTABLE?
  75. How can I create a SAS data set without using program?
  76. What is the function of LENGTH statement?
  77. Who can manipulate SAS configuration file?
  78. Explain LRECL=n option in INFILE statement?
  79. What is difference between $n. and :$n.?
  80. What is &$n.?
  81. What is @@?
  82. Write some options commonly used in INFILE statement.
  83. What is difference between compile and execution stages?
  84. What is program data vector?
  85. How can I improve my knowledge about different SAS windows? 
  86. What is a SAS data set? 
  87. What is SAS data view? 
  88. SAS doesn’t allow special characters in naming data sets or variables. Why?
  89. What are SAS automatic variables? Give two examples.
  90. What is SAS data set descriptor? 
  91. Do SAS data views have data values?
  92. What do you mean by the statement: “SAS is a free-form and case-insensitive language”?
  93. Is there any difference between CARDS and DATALINES? 
  94. What is NULL statement?
  95. What are stored in a SAS catalog? 
  96. What is SAS Data Step? 
  97. Name some objects generated after SAS Data Step?  
  98. What is SAS batch mode? 
  99. How can I run SAS from RUN dialog box? 
  100. How can I run SAS from COMMAND prompt? 
  101. What is program editor window?
  102. What is Text Editor?
  103. How can I execute SAS code by writing in notepad?
  104. How can I place SAS commands on tool bar?
  105. How can I change the text color, size, font etc. of enhanced editor window?
  106. How can I disable log details?
  107. How can I send the contents of log, editor or output window into a text file or word file? 
  108. How can I send the content of a text file into SAS editor window?
  109. How can I change the setting so that SAS displays the last output instead of first ones? 
  110. What happens if I use CTRL+N in explorer window? 
  111. What happens if I use CTRL+N in libraries window?
  112. What happens if I use CTRL+N in a library window?
  113. How can you create a catalog, query or table?
  114. What is difference between query and table?
  115. How can I know about column attributes of a table?
  116. What are the object types for output window?
  117. What is TRUNCOVER?
  118. What is LOSTCARD?
  119. Differentiate between DLM and DSD options of infile statement?
  120. What is difference between & and : format modifiers?
  121. What is difference between input data set and output data set?
  122. What is difference between system options and data set options?
  123. What is difference between statement options and data set options? 
  124. What is YEARCUTOFF? 
  125. How is date time constants created?
  126. Write the mnemonic equivalent operators for logical operators.
  127. Give two examples of global statement. 
  128. Write various options and statements used in page layout setting?
  129. How can I print the values of _N_ of a data step?
  130. Why input buffer is not needed to read SAS data set but is required in case of reading an external file?
  131. Write the steps needed to read data from a text file(TAB delimited) using import wizard.
  132. What is difference between FIRSTOBS and OBS options?
  133. What is the role of DBMS option in PROC IMPORT?
  134. What is GETNAMES statement?
  135. What is DATAROW statement?
  136. Create a named input data text-file and read it.
  137. What is difference between KEEP statement and KEEP option?
  138. Which one is more efficient - DROP statement and DROP option? Discuss.
  139. My friend writes filepath in single quote but I write in double quote. Which one is better?
  140. What is the use of RENAME data set option?
  141. I am trying to edit some data in VIEWTABLE but editing doesn’t take place. Why?
  142. How can I display the VIEWTABLE in output window without using PROC PRINT?
  143. Discuss about Form view and Table view of a data set.
  144. How can I toggle line numbers in editor window?
  145. How can I create multiple editor windows and arrange them.
  146. What is the use of NEW WINDOW?
  147. How many data sets can be mentioned in data statement?


Updated on 6 July 2023

Tuesday, March 11, 2014

SAS- File Operations read, write, append etc.

By Ajeet Kumar


/* File Reading Program Number: 1 */
/*list input style*/
DATA list ;
input Name $ Age Height ;
datalines;
Amit  22  111
Sumit 21 121                                
Mina 11 90
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 2 */
/*list input style*/
DATA list ;
input Name $ Age Height ;
datalines;
Amit    22
Sumit 21 121
Mina 11 90
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 3 */
/*list input style*/
DATA list ;
infile datalines ;
input Name $ Age Height ;
datalines;
Amit    22  111
Sumit 21 121
Mina 11 90
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 4 */
/*list input style*/
DATA list ;
infile datalines missover;
input Name $ Age Height ;
datalines;
Amit    22  111
Sumit 21
Mina 11 90
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 5 */
/*list input style*/
DATA list ;
infile datalines missover;
input Name $ Age Height State $;
datalines;
Amit    22  111 UK
Sumit 21 112 UP
Mina 11 90 MP
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 6 */
/*list input style*/
DATA list ;
infile datalines missover;
input Name $ Age Height State $;
datalines;
Amit    22  111 UK
Sumit 21 112
Mina 11 90 MP
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 7 */
/*list input style*/
DATA list ;
infile datalines stopover;
input Name $ Age Height State $;
datalines;
Amit    22  111 UK
Sumit 21 112
Mina 11 90 MP
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 8 */
/*list input style*/
DATA  ;
infile datalines stopover;
input Name $ Age Height State $ ;
datalines;
Amit    22e  111 UK
Sumit 21 112
Mina 11 90 MP
Ramesh 25 78 TN
Taimur 43 56 RS
;
run;
proc print data = list ;
run;

/* File Reading Program Number: 9 */
proc contents data = class ; run;
data class1(drop = remarks);
set class ;
run;
proc print data = class1; run;
proc sql;
drop table class;
data class;
set class1;
run;

/* File Reading Program Number: 10 */
proc contents data = class ; run;
data class1(drop = remarks);
set class ;
run;
proc print data = class1; run;
proc sql;
drop table class;
data class2(label="Bharti Reported Data");
set class1;
run;
data Bharti Reported Data ;
set class1;
run;

/* File Reading Program Number: 11 */
data read;
infile "D:\SAS Class Sonam\Bharat.txt" missover;
input Name $ Gender $ State $ Age Height Weight ;
run;

/* File Reading Program Number: 12 */
data ;
infile "D:\SAS Class Sonam\Bharat.txt" obs = 3;
input Name $ Gender $ State $ Age Height Weight ;
run;
proc print ; run;

/* File Reading Program Number: 13 */
data ;
infile "D:\SAS Class Sonam\Bharat.txt" firstobs =3 obs = 6;
input Name $ Gender $ State $ Age Height Weight ;
run;
proc print ; run;

/* File Reading Program Number: 14 */
data ;
infile "D:\SAS Class Sonam\comma.txt" dlm=',' ;
input Name $ Gender $ State $ Age Height Weight ;
run;
proc print ; run;

/* File Reading Program Number: 15 */
data ;
infile "D:\SAS Class Sonam\colon.txt" dlm=':,' ;
input Name $ Gender $ State $ Age Height Weight ;
run;
proc print ; run;

/* File Reading Program Number: 16 */
data column (label=column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2;
input       @1 Name $
            @9 Gender $
            @11 State $
            @14 Age
            @17 Height
            @20 Weight ;
run;

/* File Reading Program Number: 17 */
data column1 (label=column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2;
input       @1 Name $
            @9 Gender $
            @17 Height
            @20 Weight ;
run;

/* File Reading Program Number: 18 */
data column2 (label=column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2;
input       @1 Name $
            @9 Gender $
            @17 Height
            @20 Weight
            @11 State $
            @14 Age ;
run;

/* File Reading Program Number: 19 */
data column3 (label=column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2;
input       @1 Name $
            @9 Gender $
            @17 Height
            @20 Weight
            @11 State $
            @14 Age
            @14 Ages;
run;

/* File Reading Program Number: 20 */
data column4 (label=column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2;
input       @1 Name $
            @9 Gender $
            @17 Height
            @20 Weight
            @11 State $
            @14 Age
            @14 Age;
run;

/* File Reading Program Number: 21 */
options noreplace;
data good.column4 (label=column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2;
input       @1 Name $
            @9 Gender $
            @17 Height
            @20 Weight
            @11 State $
            @14 Age
            @14 Agexx;
run;

/* File Reading Program Number: 22 */
data formatt (label=Format Input Style);
infile "D:\SAS Class Sonam\Separatef.txt" firstobs=2;
input       Name  $ Gender $ State $ Age HT Salary comma9.2;
run;
proc print data = formatt;run;

/* File Reading Program Number: 23 */
data Dollar (label=Format Input Style);
infile "D:\SAS Class Sonam\Separated.txt" firstobs=2 obs=5;
input       Name  $ Gender $ State $ Age HT Salary dollar10.2;
run;
proc print data = Dollar;run;

/* File Reading Program Number: 24 */
data Dollar (label=Named Input Style);
infile "D:\SAS Class Sonam\Separaten.txt" ;
input       Name=   $
            Gender= $
            State=  $
            Age=
            Height=
            Salary= dollar10.2;
run;
proc print data = Dollar;run;

/* File Reading Program Number: 25 */
data startend (label=Column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2 ;
input       Name $ 1-8
            Gender $ 9-10
            Height 17-19
            Weight 20-22
            State $ 11-12
            Age 14-15 ;
run;

/* File Reading Program Number: 26 */
data AtStartend (label=Column Input Style);
infile "D:\SAS Class Sonam\Separatec.txt" firstobs=2 ;
input       @1 Name $
            Gender $ 9-10
            Height 17-19
            Weight 20-22
            State $ 11-12
            Age 14-15 ;
run;

/* File Reading Program Number: 27 */
data MoreThan8(label=List Input Style);
infile "D:\SAS Class Sonam\Separatee.txt" firstobs=2 ;
input Name $ Gender $ State $ Height Weight  Age ;
run;
proc print data = MoreThan8 ;
run;

/* File Reading Program Number: 28 */
data MoreThan8(label=List Input Style);
infile "D:\SAS Class Sonam\Separateg.txt" firstobs=2;
input Name $18. Gender $ State $ Height Age Weight ;
run;
proc print data = MoreThan8 ;
run;

/* File Reading Program Number: 29 */
data MoreThan8(label=List Input Style);
infile "D:\SAS Class Sonam\Separatee.txt" firstobs=2;
input Name : $18. Gender $ State $ Height Age Weight ;
run;
proc print data = MoreThan8 ;
run;

/* File Reading Program Number: 30 */
data ;
infile "D:\SAS Class Sonam\csv.csv" dsd ;
input Name $ Gender $ State $ Age Height Weight ;
run;
proc print ; run;

/* File Reading Program Number: 31 */
data ;
infile "D:\SAS Class Sonam\csv.csv" dsd lrecl=1000;
input Name $ Gender $ State $ Age Height Weight ;
run;
proc print ; run;

/* File Reading Program Number: 32 */
data;
informat date_of_birth MMDDYY10. ;
input date_of_birth;
cards;
11/09/2010
02/02/1999
02/23/1956
01/01/1960
10/10/1960
12/12/1959
;
run;
proc print;run;

/* File Reading Program Number: 33 */
data;
informat date_of_birth MMDDYY10. ;
input date_of_birth;
format date_of_birth MMDDYY10. ;
cards;
11/09/2010
02/02/1999
02/23/1956
01/01/1960
10/10/1960
12/12/1959
;
run;
proc print;run;

/* File Reading Program Number: 34 */
data;
informat date_of_birth MMDDYY10. ;
input date_of_birth;
format date_of_birth Date9. ;
cards;
11/09/2010
02/02/1999
02/23/1956
01/01/1960
10/10/1960
12/12/1959
;
run;
proc print;run;

/* File Reading Program Number: 35 */
data;
informat date_of_birth MMDDYY10. ;
input date_of_birth;
format date_of_birth ddmmyy10. ;
cards;
11/09/2010
02/02/1999
02/23/1956
01/01/1960
10/10/1960
12/12/1959
;
run;
proc print;run;

/* File Reading Program Number: 36 */
data;
input date_of_birth : mmddyy10.;
dob1 = date_of_birth;
dob2 = date_of_birth;
dob3 = date_of_birth;
dob4 = date_of_birth;
format date_of_birth ddmmyy10b. ;
format dob1 ddmmyy10c. ;
format dob2 ddmmyy10d. ;
format dob3 ddmmyy10n. ;
format dob4 ddmmyy10p. ;

cards;
1/09/2010
2/02/1999
2/23/1956
1/01/1960
10/10/1960
12/12/1959
;
run;
proc print;run;

/* File Reading Program Number: 37 */
data ;
infile "D:\SAS Class Sonam\Bharat.txt" missover;
length Name $ 9 Gender $ 1 ;
input Name $ Gender $ State $ x1 - x3 ;
run;
proc print ;run;

/* File Reading Program Number: 38 */
data solved;
infile "D:\SAS Class Sonam\Bhism1.txt" ;
input Name : $10. Age;
run;
proc print ;run;

/* File Reading Program Number: 39 */
data solved;
filename fileref1  "D:\SAS Class Sonam\Bhism.txt" ;
infile fileref;
input Name : $10. Age;
run;
proc print ;run;

/* File Reading Program Number: 40 */
libname fileref  "D:\SAS Class Sonam\Bhism" ;
data fileref.Sales;
infile fileref;
input Name : $10. Age;
run;
proc print ;run;

/* File Reading Program Number: 41 */

data singleat;
input name $  gender $ @;
if gender ='m';
input age income ;
cards;
anuja f 22 20000
pooja f 24 28880
amit m 22 28000
ganesh m 29 30000
hira m 55 77800
rina f 32 77000
;
run;

/* File Reading Program Number: 42 */
data doubleat ;
input colors $ @@ ;
cards ;
w w w  r g b r g b r g b r g b r g b r g b w w
r g w w r g w w r g w w r g w w r g w w r g
;
run;

/* File Reading Program Number: 43 */

data singleat1;
input @'http:\\' website : $20.;
cards;
anuja f 22 http:\\www.yahoo.com 20000
pooja f 24 http:\\www.yah.com 28880
amit m 22 http:\\www.rax.com 28000
ganesh m 29 http:\\www.yoo.com 30000
hira m 55 http:\\www.hoo.com 77800
rina f 32 http:\\www.koo.com 77000
;
run;

SAS- Miscellaneous Topics



SAS PROGRAMS FOR ABSOLUTE BEGINNERS BY AJEET KUMAR


/* Miscellaneous Program Number: 1 */
data dated ;
input dob :mmddyy10.;
format dob date9. ;
datalines;
1/1/1960
1/2/1960
1/3/1960
1/1/1959
11/17/2013
;
run;
proc print data =dated;
run;

/* Miscelleneous Program Number: 2 */
data date1 ;
informat dob mmddyy10. ;
input dob ;
format dob date9. ;
datalines;
01/01/1960
1/2/1960
1/3/1960
1/1/1959
11/17/2013
;
run;
proc print data =date1;
run;

/* Miscelleneous Program Number: 3 */
data date1 ;
input dob mmddyy10. ;
year=year(dob);
month=month(dob);
day=day(dob);
date= mdy(month, day, year);
format dob date9. date date9.;
DaysPassed= today()- dob;
DaysPassedSinceX= '15NOV2013'd - dob;
datalines;
01/01/1960
1/2/1980
1/3/1980
11/1/1959
4/17/1993
;
run;
proc print data =date1;
run;

/* Miscelleneous Program Number: 4 */
data prefix;
input sales_price sales_qty ;
sales_rev = sales_price * sales_qty ;
datalines;
12.4 23
13.5 32
;
run;
proc print data = prefix ;
var sales_: ;
run;

data list_num;
input x1 - x5 ;
datalines;
12.4 23 33 54 33
13.5 32 32 65 66
;
run;
proc print data = list_num ;
run;

proc contents data = sashelp.class varnum;
run;
data ddash;
set sashelp.class;
run;
proc print data = ddash ;
var sex -- weight ;
run;

proc print data = ddash ;
var _character_ ;
run;

proc print data = ddash ;
var _numeric_ ;
run;

proc print data = ddash ;
var _all_ ;
run;

/* Miscelleneous Program Number: 5 */
data miss;
missing xa ;
infile cards missover ;
input name $ age weight gender $;
cards;
amit 23 421 M
sumit 12 x M
vimla 44 a F
;
run;
proc print data = miss ;
run;

/* Miscelleneous Program Number: 6 */
options missing = xa ; /* global */
data miss;
infile cards missover ;
input name $ age weight gender $;
cards;
amit 23 421 M
sumit 12 x M
vimla 44 a F
;
run;
proc print data = miss ;
run;

/* Miscelleneous Program Number: 7 */
data missin;
missing xa ;
input name $ age weight gender $;
if weight = .a or weight = .x ;
cards;
amit 23 421 M
sumit 12 x M
vimla 44 a F
;
run;
proc print data = missin ;
run;

/* Miscelleneous Program Number: 8 */
data sorty;
missing xa ;
input name $ age weight gender $;
cards;
amit 23 4 M
sumit 12 x M
vimla 44 a F
Ravi 22 -2 M
Tanu 32 0 M
Kanta 12 . F
;
run;
proc sort data = sorty ;
by weight ;
run;
proc print data = sorty ;
run;

/* Miscelleneous Program Number: 9 */
data missin;
missing xa ;
input name $ age weight gender $;
if weight = . ;
cards;
amit 23 421 M
sumit 12 . M
vimla 44 . F
;
run;
proc print data = missin ;
run;

/* Miscelleneous Program Number: 10 */
data date1 ;
informat dob mmddyy10. ;
input dob ;
format dob ddmmyyb10. ;
datalines;
01/01/1960
1/2/1960
1/3/1960
1/1/1959
11/17/2013
;
run;
proc print data =date1;
run;

data date1 ;
informat dob mmddyy10. ;
input dob ;
format dob ddmmyyc10. ;
datalines;
01/01/1960
1/2/1960
1/3/1960
1/1/1959
11/17/2013
;
run;
proc print data =date1;
run;
data date1 ;
informat dob mmddyy10. ;
input dob ;
format dob ddmmyyd10. ;
datalines;
01/01/1960
1/2/1960
1/3/1960
1/1/1959
11/17/2013
;
run;
proc print data =date1;
run;
data date1 ;
informat dob mmddyy10. ;
input dob ;
format dob mmddyyp10. ;
datalines;
01/01/1960
1/2/1960
1/3/1960
1/1/1959
11/17/2013
;
run;
proc print data =date1;
run;
data date1 ;
informat dob mmddyy10. ;
input dob ;
format dob mmddyys10. ;
datalines;
01/01/1960
1/2/1960
1/3/1960
1/1/1959
11/17/2013
;
run;
proc print data =date1;
run;

/* Miscelleneous Program Number: 11 */
data operate;
input x y;
plus = x + y;
minus = x - y;
product = x * y;
division = x / y;
exponent = x ** y ;
band = x and y ;
bor = x or y ;
notx = not x ;
Less = x lt y ;
maximum = x <> y ;
minimum = x >< y ;
cards;
0 2
6 2
;
run;
proc print data = operate ;
run;


/* Miscelleneous Program Number: 12 */
data _null_;
infile "D:\abc1.txt";
file "D:\abc2.txt";
input;
put _infile_;
run;

/* Miscelleneous Program Number: 13 */
proc contents data = sashelp.class;
run;
proc datasets ;
contents data = sashelp._all_ nodetails;
quit;

proc datasets;
contents data=sasuser.admit varnum;
quit;
options nonumber nodate ps=88 ls=99 firstobs=2 obs=9 yearcutoff=1990;
proc print data=clinic.admit;
var id sex age height weight;
where age>=30;
run;
options date source leftmargin=11 user=sashelp errors=5 nofmterr;
proc freq data=clinic.diabetes;
where fastgluc>=300;
tables sex;
run;


/* Miscelleneous Program Number: 14 */
proc copy in=work out=good move ;
select ssss;
run;

/* Miscelleneous Program Number: 15 */
PROC EXPORT DATA= WORK.Class
            OUTFILE= "C:\Documents and Settings\class\My Documents\class.txt"
            DBMS=TAB REPLACE;
RUN;

/* Miscelleneous Program Number: 16 */
data ;
input x y @@ ;
file print;
put _all_;
put _PAGE_;
cards;
1 2 3 4 5 5
;
run;

/* Miscelleneous Program Number: 17 */
options ps =111 nocenter;
data miss;
input Age @@ ;
if Age = . then abort ;
put _all_ ;
datalines;
22 34 3 45 56 34 45 67 . . 44 5 . 44
;
run;
proc print data = miss ; run;


/* Miscelleneous Program Number: 18 */
data rare;
input X @;
if X= . then error "Error prints message in log";
input Name $ @@ ;
cards;
1 One 2 Amar 3 Danny 4 Rina
5 Five . Six 7 Seven . Eight
;
run;
proc print data=rare;
run;

/* Miscelleneous Program Number: 19 */
data class;
set sashelp.class;
/*if 10 < Age <= 15 then AgeGrp = 3 ;*/
/*if 15 < Age <= 20 then AgeGrp = 4 ;*/
AgeGrp = 2 + ( Age >= 10) + ( Age >= 15) ;
run;
proc print data = class ; run;


/* Miscelleneous Program Number: 20 */
options ps =111 nocenter;
data class;
set sashelp.class;
Category = ifc( Age > 13, 'Adolsc', 'Child');
PocketMoney = ifn( Age > 13, 111, 55);
run;
proc print data = class ; run;


/* Miscelleneous Program Number: 21 */
options ps =111 nocenter;
data miss;
input Age @@ ;
if not (Age = .) then output;
datalines;
22 . . 44 5 . 44
;
run;
proc print data = miss ; run;


/* Miscelleneous Program Number: 22 */
/*options _last_ = data1;*/
data miss;
infile datalines ;
input Gender $ Age @@ ;
if missing(Age) then delete;
/*if Age = . then delete ;*/
datalines;
M 33 F . M 11 M 31 M 12 M 22 F .
F 11 F 32 M 21 F 28 F 21 F 22 M .
;
run;
proc print data=miss; run;

/* Miscelleneous Program Number: 23 */
/*nobs implies number of obs*/
/*point option of set statement determines the obs to be read*/
data small;
do obsnum = 1 to total by 2;
set sashelp.class point=obsnum nobs=total;
if _error_ then abort;
output;
end;
stop;
run;
proc print data=small;run;
/*proc print data=sashelp.class;run;*/

/* Miscelleneous Program Number: 24 */
data sim;
do i=1 to 20;
group = int(5 * ranuni(54321)) + 1;
y = rannor(12345);
output;
end;
keep group y;
run;
proc print data=sim;
run;

/* Miscelleneous Program Number: 25 */
data rare;
input X @;
if X= . then return;
input Name $ @@ ;
cards;
1 One 2 Amar 3 Danny 4 Rina
5 Five . Six 7 Seven . Eight
;
run;
proc print data=rare;
run;

/* Miscelleneous Program Number: 26 */
options ps =111 nocenter;
data miss;
input Age @@ ;
if Age = . then stop ;
datalines;
22 34 3 45 56 34 45 67 . . 44 5 . 44
;
run;
proc print data = miss ; run;


/* Miscelleneous Program Number: 27 */
options validmemname=extend validvarname=any;
data  datachar ;
input ' var name 'n $;
datalines;
2
2
3
4
;
run;

/* Miscelleneous Program Number: 28 */
options validmemname=extend validvarname=any;
data  convar;
input ' var name 'n $ convar $;
convar = 'Rs.' || ' var name 'n ;

datalines;
2
2
3
4
;
run;

/* Miscelleneous Program Number: 29 */
data _null_;
window start
#9 @26 'WELCOME TO THE SAS SYSTEM' color=blue
#12 @19 'THIS PROGRAM CREATES'  color= red
#12 @40 'TWO SAS DATA SETS' color=brown
#14 @26 'AND USES THREE PROCEDURES'
#18 @27 'Press ENTER to continue';
display start;
stop; run;

/* Miscelleneous Program Number: 30 */
proc contents data= class;
run;
proc contents data= class varnum;
run;
proc contents data= class directory;
run;
proc print data = class;
run;
proc sort data = class ;
by name ;
run;

Hot Topics