BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rfarmenta
Obsidian | Level 7

I work with survey data and we have a short and a long survey. The long survey contain everything the short survey has with additional questions. If a person completes the short survey we want to set all of the other variables in the dataset for them to special missing, something like .l . We also have a variable to indicate the type of survey. Is there an easy way to do this? Thank you for your help.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Easiest might be an array of the response variables you want to set and in a data step:

supposing that questions q23-q50 are the ones you need to set special missing then:

array NA q23-q50;

do i=1 to dim(NA);

   NA[i] = .i;

end;

drop i;

 

 

Text variable don't use special missing though.

 

View solution in original post

6 REPLIES 6
ballardw
Super User

Easiest might be an array of the response variables you want to set and in a data step:

supposing that questions q23-q50 are the ones you need to set special missing then:

array NA q23-q50;

do i=1 to dim(NA);

   NA[i] = .i;

end;

drop i;

 

 

Text variable don't use special missing though.

 

rfarmenta
Obsidian | Level 7

Hmm..That code works the only problem is I have about 300 variables that are not on the short survey but 78 on the short survey. Is there a way to reverse it so I include the variable names from the short survey?

rfarmenta
Obsidian | Level 7

Actually, I was able to get it to work. I added in the following:

 

if short[i]=. then short[i]=.l;

 

Thank you for your help!

 

 

ballardw
Super User

@rfarmenta wrote:

Actually, I was able to get it to work. I added in the following:

 

if short[i]=. then short[i]=.l;

 

Thank you for your help!

 

 


Be careful with this approach if you have skip patterns in the survey data or other missing values that are not due to the survey length. You may generate special missing when not intended.

rfarmenta
Obsidian | Level 7

Thank you. The skip patterns is not an issues because we are going to code those as special missing separately. I did realize that my code does not work for what I want though. Are there any other ways to do this? Otherwise I will have to just include all of the variable names. Thank you!

 

ballardw
Super User

It may help to use variable lists if your variable names are amenable, such as my example. If you have blocks of questions that all the names that start with some common stem that you need to address then you can use something like:

 

array NA qabc:  qpdq: ;

to shorten the amount of code you need to write. The above would place all variables whose names that start with qabc and qpdq into the array but not those that start with qabb or qpdm for instance.

or if the variables you need appear in order you can use the -- in the list to specify variables from to such as

 

array NA qabc -- qpdq; which would include the variables in order from qabc to qpdq.

You can mix these (carefully) or use multiple lists. For instance if you have blocks of questions in your long survey such that only the first question was asked in the short then array definiton might look like

 

array NA block1Q2 -- block1Qn  block2Q2 -- block2Qn ; Where block1q2 means the second question (or the first unasked in the short form) and block1Qn means the last unasked within that section of questions.

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!

How to Concatenate Values

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.

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
  • 6 replies
  • 1249 views
  • 0 likes
  • 2 in conversation