Hi, I'm struggling with this question below. Your input is much appreciated!
data all; infile ‘ubaacs.survey.tariff ’; input type $1. @; if type=’m’ then do; input nreps 2. id $2.; do i=1 to nreps; input uear rate; output; end; end; run;
m 3us
87 5.4
88 5.15
89 5.0
i 1us
9.7 11.2
m 2it
88 6.0
89 5.8
What will dataset all look like???
You can avoid having to access an external file by using inline data with the datalines file reference and datalines statement:
data all;
infile datalines;
input type $1. @;
if type = 'm' then do;
input nreps 2. id $2.;
do i = 1 to nreps;
input uear rate;
output;
end;
end;
datalines;
m 3us
87 5.4
88 5.15
89 5.0
i 1us
9.7 11.2
m 2it
88 6.0
89 5.8
;
Note:
You could actually run the code, and find out the answer that way.
You create a text file, with the name given in the infile statement, and then you run the code.
By the way, it seems as if the code you showed was perhaps pasted into here from Microsoft Word, in which case all of the quotes need to be replaced with "un-curly" quotes that SAS will recognize (SAS doesn't recognize the "curly" quotes).
Let's do the computer work:
the input computer work ======= ========================== m 3us type='m' and nreps=3 id='us' 87 5.4 rep1 ==> uear =88 rate=5.4 88 5.15 rep2 ==> complete it by yourself 89 5.0 rep3 ==> i 1us type ne 'm' ==> skip it 9.7 11.2 type ne 'm' ==> skip it m 2it type = 'm' and nreps=2 id='it' 88 6.0 rep1 ==> 89 5.8 rep2 ==>
What variables are in the table is determined at compile time.
The data has nothing to do with it.
Hint: you forgot one variable.
You can avoid having to access an external file by using inline data with the datalines file reference and datalines statement:
data all;
infile datalines;
input type $1. @;
if type = 'm' then do;
input nreps 2. id $2.;
do i = 1 to nreps;
input uear rate;
output;
end;
end;
datalines;
m 3us
87 5.4
88 5.15
89 5.0
i 1us
9.7 11.2
m 2it
88 6.0
89 5.8
;
Note:
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.