Dear Folks, plz help me with the following program:
data chk_10;
input sno name $ level;
if level = . then exp = 'unknown';
else if level = 1 then exp = 'low';
else if level = 2 or 3 then exp = 'medium';
else exp = 'high';
datalines;
1 Frank 1
2 John 2
3 sui 2
4 sose 1
5 burt 4
6 kelly .
7 juan 1
;
run;
proc print data = chk_10;
title 'chk1-0';
run;
I want in output that for the observation, which has level value as 4, i should get exp = 'high'--
but output is not showing that. in output - for level 4, exp is coming to be 'medium' --
but i am not able to se why is it so.
Appreciate your help-
The problem is 'if level = 2 or 3' The answer to this is always yes.
data chk_10;
input sno name $ level;
if level = . then exp = 'unknown';
else if level = 1 then exp = 'low';
else if level = 2 or level = 3 then exp = 'medium';
else exp = 'high';
datalines;
1 Frank 1
2 John 2
3 sui 2
4 sose 1
5 burt 4
6 kelly .
7 juan 1
;
run;
Another way would be to put if level > 3 then exp = 'high';
The problem is 'if level = 2 or 3' The answer to this is always yes.
data chk_10;
input sno name $ level;
if level = . then exp = 'unknown';
else if level = 1 then exp = 'low';
else if level = 2 or level = 3 then exp = 'medium';
else exp = 'high';
datalines;
1 Frank 1
2 John 2
3 sui 2
4 sose 1
5 burt 4
6 kelly .
7 juan 1
;
run;
Another way would be to put if level > 3 then exp = 'high';
The condition (LEVEL=2 or 3) is the same as ((LEVEL=2) or 3). Since 3 is always true this condition is always true.
Thanks, could you just help me with another one?
prog is:
data test_26;
infile Q26;
input empname $ 1-4;
if empname = 'Ruth' then input idnum 10-11;
else input age 7-8;
run;
proc print data = test_26;
title 'q26';
run;
input is :
Ruth 23 46
DP 45 19
Cali 34 23
Ruth 21 89
output is coming as:
empname idnum age
Ruth 19 .
Cali . 21
I understand that while reading first record, only empname is read and the pointer moves to the second row - but I am not able to understand rest of the output.
Please help.
Your first input statement
input empname $ 1-4;
tells SAS to load the contents of columns 1 to 4 into empname and step on to the next record. To keep hold of the same record in case you need to load more data from it later in the data step, you need to use the trailing @ notation:
input empname $ 1-4 @;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.