BookmarkSubscribeRSS Feed
Mirisage
Obsidian | Level 7
Hi colleagues,
I have a data set (10,000 obs) like this .

Data MDI;
Input ID Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10; /*ID=Household ID*/
cards;
1 1 2 2 1 2 1 2 1 1 1
2 2 2 2 1 1 1 1 1 1 1
3 1 1 1 1 1 1 1 1 2 1
;
Run;

I need to create a new variable called deprived where deprived=1 if you get two or more 2 s for variables Q1 to Q10, else deprived =2

For instance, the new variable deprived for these three households should get following values:

For first household, deprived =1 (because there are four 2 s)
For second household, deprived =1 (because there are three 2 s)
For third household, deprived =2 (because there is only one 2 )

Could you please help me know with the codes to create the new variable called deprived?

Thanks

Neil
3 REPLIES 3
Patrick
Opal | Level 21
Neil

Your sample shows only the values '1' or '2' for the q variables. If this is true then the following should work:

if sum(of q:)>=12 then deprived=2;
else deprived=1;

HTH
Patrick

Message was edited by: Patrick
Mirisage
Obsidian | Level 7
Hi Patrick,

Your codes worked perfectly. Many thanks.

However, I couldn't mention that some households responded for Q variables like this:
Don’t know or Refused or Not stated.
The codes for above three responses are 7, 8 and 9 respectively.

In that case, how could I handle this situation?

Thanks

Neil
data_null__
Jade | Level 19
concatenate, compress, count, test

[pre]
deprived = ifN(lengthN(compress(cats(of q:),'2','K')) ge 2,1,2);
[/pre]

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1161 views
  • 0 likes
  • 3 in conversation