BookmarkSubscribeRSS Feed
EmmaW
Calcite | Level 5

I've been trying to perform a row sum for 14 variables in my data set. 

Here's my code: 

DATA temp;
set work.silver2;
sum_chronic=q2a_temp + q2b_temp + q2c_temp + q2d_temp + q2e_temp + q2f_temp + q2g_temp + q2h_temp + q2i_temp + q2j_temp + q2k_temp + q2l_temp + q2m_temp + q2n_temp;
run;

Every time I run the data, it tells me that the variables are unintialized, but this is the same "data" line and "set" that I collapsed the variables into earlier.  Any advice for how to fix this? I'm very confused.  

4 REPLIES 4
SASKiwi
PROC Star

Please post your complete SAS log including all messages so we can see more clearly what is going on.

EmmaW
Calcite | Level 5

Here's the log output (I used the sum function instead, as another person recommended in the comments): 

2805 DATA temp;
2806 set work.silver2;
2807 chronic_disease=.;
2808
2809 IF q2a_temp = 1 THEN _q2a_temp = 1;
2810 IF q2b_temp = 1 THEN _q2b_temp = 1;
2811 IF q2c_temp = 1 THEN _q2c_temp = 1;
2812 IF q2d_temp = 1 THEN _q2d_temp = 1;
2813 IF q2e_temp = 1 THEN _q2e_temp = 1;
2814 IF q2f_temp = 1 THEN _q2f_temp = 1;
2815 IF q2g_temp = 1 THEN _q2g_temp = 1;
2816 IF q2h_temp = 1 THEN _q2h_temp = 1;
2817 IF q2i_temp = 1 THEN _q2i_temp = 1;
2818 IF q2j_temp = 1 THEN _q2j_temp = 1;
2819 IF q2k_temp = 1 THEN _q2k_temp = 1;
2820 IF q2l_temp = 1 THEN _q2l_temp = 1;
2821 IF q2m_temp = 1 THEN _q2m_temp = 1;
2822 IF q2n_temp = 1 THEN _q2n_temp = 1;
2823
2824 SUMRACE=
2824! sum(_q2a_temp,_q2b_temp,_q2c_temp,_q2d_temp,_q2e_temp,_q2f_temp,_q2g_temp,_q2h_temp,_q2i_tem
2824! p,_q2j_temp,_q2k_temp,_q2l_temp,_q2m_temp,_q2n_temp);
2825 RUN;

NOTE: Variable q2a_temp is uninitialized.
NOTE: Variable q2b_temp is uninitialized.
NOTE: Variable q2c_temp is uninitialized.
NOTE: Variable q2d_temp is uninitialized.
NOTE: Variable q2e_temp is uninitialized.
NOTE: Variable q2f_temp is uninitialized.
NOTE: Variable q2g_temp is uninitialized.
NOTE: Variable q2h_temp is uninitialized.
NOTE: Variable q2i_temp is uninitialized.
NOTE: Variable q2j_temp is uninitialized.
NOTE: Variable q2k_temp is uninitialized.
NOTE: Variable q2l_temp is uninitialized.
NOTE: Variable q2m_temp is uninitialized.
NOTE: Variable q2n_temp is uninitialized.
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
596 at 2824:16
NOTE: There were 596 observations read from the data set WORK.SILVER2.
NOTE: The data set WORK.TEMP has 596 observations and 327 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 second

 

When I was cleaning up the variables before trying to do this sum, I was using the format: 

2702
2703 DATA temp;
2704 Set work.silver2;
2705 q2m_temp=.;
2706 IF (Q2m=1) then q2m_temp=0;
2707 IF (Q2m=2) then q2m_temp=1;
2708 IF (Q2m=98) then q2m_temp=98;
2709 IF (Q2m=99) then q2m_temp=99;
2710 IF (Q2m=901) then q2m_temp=901;
2711 LABEL q2m_temp="q2m_temp";
2712 RUN;

 

That seemed to be working just fine and I was getting the output that I needed using the same recode format for all 14 variables.  The data set doesn't have missing variables, although once I get a sum formula that works, I will have to initialize the 98, 99 and 901 to missing before adding (I think).  I'm very new at this, so any advice is welcome

Tom
Super User Tom
Super User

If it did not generate the uninitialized variable message before then something has changed.

If the code did not change then the dataset SILVER2 has changed. It no longer has those variables.

ballardw
Super User

Show us the result of Proc Contents on the data set Work.silver2. Just need the section of the variable names and types.

 

Hint: Unless your desired behavior is to have a missing value when any of the variables on that addition statement are missing I would suggest using the SUM function which will total the non-missing values. The + operator will return missing if ANY of the values is missing. Note that this means that if every observation has one or more missing values for the q2 _temp variables then Sum_chronic would be missing for every observation.

 

I don't know who suggested naming variables q2a_temp q2b_temp etc. If those had been named Temp_q2a Temp_q2b etc. You might be able to use the list short cut of temp_q2:  to use all the variables whose names start with temp_q2 so that long statement could reduce to

 

sum_chronic = sum(of temp_q2:);

 

And the A, B, C etc suffixes might be better, at least in terms of SAS coding as 1, 2, 3 such as Temp_q2_1 Temp_q2_2 Temp_q2_3 because there are places where enumerated lists such at Temp_q2_3 - Temp_q2_10 to use the 3rd through 10th of the temp q2 variables might be handy. The character suffix doesn't play nice with sequences in names.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 237 views
  • 0 likes
  • 4 in conversation