You are on page 1of 6

Question (2012)

Dataset below shows the hospital visit by patients during the entire year data hospital; input name $ month $; cards; Tanu Jan Tanoj Feb Tanu Apr Tanu Dec Arun Oct Kiran Nov Tarun Mar Tarun Apr Tarun May Tarun Dec ; run; Find out how many times each patient has visited the hospital in 2012-08-12 using proc freq, proc report, proc sql Answer: proc freq data = hospital; tables name/out=hosp1(drop=percent); run; data hosp2; set hospital; count=1; run; proc report data = hosp2; column name count; define name/group; run; proc sql; select name, sum(count) from hosp2 group by name; ?

quit; Question: data class; input name $ subject $ marks; cards; Manoj Sacience 94 Raj Science 86 Tanu Maths 76 Manoj Maths 45 Manoj English 65 Tanu English 76 Tanu Science 76 Raj Maths 66 Raj English 56 ; run; Use SQL to produce : Sum as 204 208 228 68 76 Manoj Raj Tanu Manoj Raj Tanu

Avg Marks as: 69.33333

Use proc means to do the same Answer: proc sql; select name, Avg(marks) from class group by name; quit; proc sort data = class; by name; run; proc means data = class mean; var marks;

by name; run; Reading External Data in SAS System below: 01APR90 68 02APR90 67 03APR90 70 04APR90 74 05APR90 72 06APR90 73 07APR90 71 08APR90 75 09APR90 76 SAS to read: filename myfile C:\Users\xxxnamexxx\Desktop\text1.txt; data mydat; infile myfile ; input date $ temp @@; format date yymmdd10.; run; SAS LOG: ERROR 48-59: The format $YYMMDD was not found or could not be loaded WARNING: The data set WORK.MYDAT may be incomplete. When this step was stopped there were 0 observations and 2 variables. Explain the error message Answer: The code should be written as: filename myfile C:\Users\xxxnamexxx\Desktop\text1.txt; data mydat; infile myfile ; input date : date. temp @@; format date yymmdd10.; run; SAS system was unable to read the date in correct format from external file. That is why there was error in SAS log. SAS Macros Example Leave a Comment (polls) How do you like the blog content? Question: The external file text1.txt contains the data in the format given

Question:

Dataset hired is created as data Hired; input name $ start; cards; Raj 14567 Manoj 14524 Arvin 14579 Ran 14465 Arun 14642 Kirti 14123 Ravin 14523 Suresh 14272 Lalu 14627 Vash 14770 run; Write a SAS Macro to print all those candidates who are hired in the current month. Answer:

%macro currenthire; data current; set hired; if month(start) = month(today()); run; %mend; %currenthire; Question: Create a SAS Macro to combine number of datasets (given below). Also use the macro debugging options. data file1; input a @@; cards; 1 2 3 4 ;

run; data file2; input a @@; cards; 5 6 7 8 ; run; data file3; input a @@; cards; 9 10 11 12 ; run;data file4; input a @@; cards; 13 14 15 16 ; run; Answer: Filename mprint C:\Users\abc\Desktop\macrores.sas; Options mprint mfile mlogic symbolgen ; %macro combine(n); data comb; set %do i=1 %to &n; file&i %end; ; run; %mend combine; %combine(4); Question: data xxx; Dataset xxx is given as:

input v1-v5 ind1 ind2; cards; 1 0 1 1 0 34 23 0 0 0 1 1 22 32 1 1 0 1 0 12 10 0 1 1 0 1 56 90 ; run; Create a SAS macro to print 10 reports (5*2) such that first report contains variables v1 ind1, second contains the variables v1 ind2 and so on Answer: %macro mymac(x,y); %do i=1 %to &x; %do j=1 %to &y; proc print data = xxx; var v&i ind&j; run; %end; %end; %mend mymac; %mymac(5,2);

You might also like