BookmarkSubscribeRSS Feed
jc3992
Pyrite | Level 9
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.

5 REPLIES 5
Reeza
Super User

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.

jc3992
Pyrite | Level 9
 
 
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.
 
 
Reeza
Super User

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.
 
 

 

Astounding
PROC Star

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.

ballardw
Super User

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 920 views
  • 3 likes
  • 4 in conversation