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]

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!

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.

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
  • 3 replies
  • 620 views
  • 0 likes
  • 3 in conversation