data mydata_Plus; infile '/folders/myfolders/Programs/mydata_Plus.csv'; input workshop gender $ q1 q2 q3 q4; set mydata_Plus; Array new_q q1-q4; Array old_q q1--q4; drop i; do i= 1 to 4; if old_q =. then new_q = 9; else if old_q = 4 then new_q = 4; else if old_q = 5 then new_q =.; end; run;
Hello everyone,
My attempt is to convert "." to 9, 4's to 20, and 5's to "."
The Log showed that I might have some problem during inputing the variables without setting the distance.
Is there anyone would like to give me some hints on how to modify my current code?
Thanks very much!
The data is as attached.
jc3992 wrote:The Log showed that I might have some problem during inputing the variables without setting the distance.
Is there anyone would like to give me some hints on how to modify my current code?
In that case, perhaps posting the log would be helpful.
That's not the full log.
@jc3992 wrote:
NOTE: Invalid data for workshop in line 1 1-27.NOTE: Invalid data for q1 in line 3 1-11.NOTE: Invalid data for q2 in line 4 1-11.NOTE: Invalid data for q3 in line 5 1-2.NOTE: Invalid data for q4 in line 5 4-8.
The SET statement definitely doesn't belong. You are inputting from raw data, and don't need to bring in a SAS data set.
Technically, you could (and should) use one array instead of two. This statement would be perfectly acceptable:
if new_q{i} = . then new_q{i} = 9;
Note the proper way to refer to a variable in the array. Since "i" is the variable used in the DO loop, it has to be the variable used to reference array elements.
When you attempt to use arrays you need to point to which element of the array to use:
Perhaps
do i= 1 to 4; if old_q[i] =. then new_q[i] = 9; else if old_q[i] = 4 then new_q[i] = 20; else if old_q[i] = 5 then new_q[i] =.; end;
The value of i is the index that points to which of the array varibles/values to consider.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.