DATA Step, Macro, Functions and more

solve question - based on creating a new variable on basis of 6 existing variable

Reply
New Contributor
Posts: 4

solve question - based on creating a new variable on basis of 6 existing variable

[ Edited ]

 

I dont have any data but i have to give a sample code for how i would solve such a problem.

the problem is to Create a variable decision_pt  that sums the occurences of the following 

    1. age < 45
    2. state is “URBAN” or “HIGHLY URBAN”
    3. furniture >= 5
    4. premium = yes
    5. usage = “COMMERCIAL”
    6. male = 1
data a;
set a;
retain decision_pt = 0;
if age < 45 then decision_pt =decision_pt +1 ;
if state ="URBAN" or "HIGHLY URBAN" decision_pt =decision_pt +1 ;

am i on the right track?

Respected Advisor
Posts: 2,833

Re: solve question - based on creating a new variable on basis of 6 existing variable

You can't expect us here in SAS Communities to do your homework for you! You will not learn anything that way.

 

So here's my suggestion: you write some SAS code to do this, and if you can't get it to work, show us the code and the SASLOG, and someone here will know how to fix it.

--
Paige Miller
New Contributor
Posts: 4

Re: solve question - based on creating a new variable on basis of 6 existing variable

Posted in reply to PaigeMiller

i modified the question with my answer now. hope this helps.

Respected Advisor
Posts: 2,833

Re: solve question - based on creating a new variable on basis of 6 existing variable

Seems like this could produce the desired answer, once you clean up your syntax errors.

 

if state ="URBAN" or state="HIGHLY URBAN" then decision_pt =decision_pt +1 ;
--
Paige Miller
New Contributor
Posts: 4

Re: solve question - based on creating a new variable on basis of 6 existing variable

Posted in reply to PaigeMiller

Is adding retain important here?

Respected Advisor
Posts: 2,833

Re: solve question - based on creating a new variable on basis of 6 existing variable

[ Edited ]

RETAIN probably isn't needed here, and may have undesired effects.

 

I think you want

 

decision_pt=0;

 

--
Paige Miller
Ask a Question
Discussion stats
  • 5 replies
  • 119 views
  • 0 likes
  • 2 in conversation