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

Hello, I know the title isn't very clear and I apologize for that and here is some info to help make what I'm asking about make more sense:

 

I am a first-semester student in a social science/human ecology PhD program, so I am looking at behaviors and outcomes and pretty new to this. I am using a secondary dataset and I am trying to create a scale variable (that has been created and used this way in other research- though was concerned with a different outcome/relationships. Including using the same secondary data I am using- though from a different wave of the data). I am not concerned with the degree to which a certain behavior or circumstance is present, just whether or not it is present and the effect of that on a particular outcome.

 

Right now I have created 10 binary dummy variables that are either 0 or 1 (0=behavior/circumstance is not present, 1=behavior/circumstance is present). I want to now create a new variable that will add up the dummy variables to have a value of 0-10, so that in the end the variable will represent a score from 0-10. I just am not sure how to do that from here.

 

Thank you for any help/direction.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Do you mean this? In a DATA step:

new_varuable = sum(of dummy1-dummy10);

View solution in original post

7 REPLIES 7
Astounding
PROC Star
Do you mean this? In a DATA step:

new_varuable = sum(of dummy1-dummy10);
Calyn
Fluorite | Level 6

I kept getting an error, so I searched using the sum terminology and was able to search for that for other options. So I just wanted to follow up with what I ended up doing that seems to have worked. I don't know enough about SAS to know why or why not, but wanted to follow up to make sure this looked alright?

 

DATA work.set_SAS; SET filesave.set_SAS;  

/*creating new variable for scale*/

NEW=.; 

/*recoding new variable for scale*/

NEW=var1-var2-var3-var4-var5-var6-var7-var8-var9-var10; 

LABEL NEW= "Scale (0-10)"; 

RUN;

Astounding
PROC Star

If you post the log with the error, it should be easy to diagnose.

 

Your formula runs without error, but isn't the same thing.  You would need to change the minus signs to plus signs to get the right result.

ballardw
Super User

If you use the + instead of Sum you get missing value result if any of the variables have missing values. So that is something to consider as well.

 

data example;
    v1 =1;
    v2 =0;
    v3 =.;
    v4 = 3;
    v5 = 4;
    tot = v1 + v2 + v3 + v4 + v5;
    total = sum (of v1-v5);
run; 
Calyn
Fluorite | Level 6
Thank you! I found that out and also realized I had been messing up creating some of my empty variables so that they actually pulled the values over correctly. So I've been rewriting and checking the variables means this time to make sure. That and figuring out how to sum the scale variable so that it works has basically been my morning 😃

I really appreciate the help with this! I know that it will get easier, but right now it feels like one big game of whack a mole 😉

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1321 views
  • 3 likes
  • 3 in conversation