I have to get this code into a frequncy table.
Data Ques;
Input ID $ Reason1-Reason4;
Datalines;
001 3 6 13 17
002 8 3 4 .
003 20 2 . .
004 8 4 20 19
;
The code format I used and that my textbook suggested to do this goes like:
Data Ques;
Input ID $ Reason1-Reason4;
Datalines;
001 3 6 13 17
002 8 3 4 .
003 20 2 . .
004 8 4 20 19
;
Proc Sort Data=Ques;
by ID;
run;
Data Ques;
array count[4] Reason1-Reason4;
do Reason=1 to 4;
Dist=count[Reason];
Output;
end;
run;
Proc Print Data=ques;
run;
For some reason this doesn't seem to be working for me, and it returns a table full of missing values. The only difference I can perceive from my code and the book's code for the exact same problem is that their example contains a set statement referencing a example dataset.
You left out the SET statement so the data step has no data to actually output.
You will be better off if you don't overwrite the original data. Use a different name on the DATA statement than on the SET statement.
data ques_tall;
set ques;
array count[4] Reason1-Reason4;
do Reason=1 to 4;
Dist=count[Reason];
output;
end;
run;
proc print data=ques_tall;
run;
You can skip the ARRAY and the extra data step and just read the values into the "tall" structure to begin with.
data ques_tall;
input ID @;
do Reason=1 to 4 ;
input Dist @;
output;
end;
datalines;
001 3 6 13 17
002 8 3 4 .
003 20 2 . .
004 8 4 20 19
;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.