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

Can anyone help me identify the problem in code below? I think it might be the first set of if statements creating _ct (count) variables. Those values are very off though in general the code runs and even the final indicators will likely be correct once I can get appropriate values for the _ct variables. 

 

Thank you for your suggestions. 

Clo13_0-1649882178732.png

 

Clo13_1-1649882272990.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
average_joe
Obsidian | Level 7

The issue seems to be how you initialize the _ct vars. Try this:

 

if first.scrssn then do;
    likely_ct = 0;
    high_likely_ct = 0;
    acute_ct = 0;
end;

 

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Explain the desired output.


And: show us the desired output for a small example data set (and show us the small example data set as well).

 

Please provide code as text, not as screen captures, pasted into the window that appears when you click on the "little running man" icon.

--
Paige Miller
Clo13
Fluorite | Level 6
Hi Paige. Agreed. I work on SAS via a remote desktop and I have to get a system down for transferring all the helpful info out of the SAS environment.
average_joe
Obsidian | Level 7

The issue seems to be how you initialize the _ct vars. Try this:

 

if first.scrssn then do;
    likely_ct = 0;
    high_likely_ct = 0;
    acute_ct = 0;
end;

 

Clo13
Fluorite | Level 6
Thank you so much! That works! I need to study more. 🙂
ballardw
Super User

The code on the if first. is almost certainly wrong unless you want to do a logical comparison between one value and the results of two other logical comparisons.

When you do something like this (and you can copy this as it is text and run in your session)

data example;
   x=3;
   if x=3 then var1=10 and var2=0 and var3=0;
run;

What SAS does when it encounters Var1 = it assumes that EVERYTHING after the = is involved with assigning the value to Var1. This gets coupled with SAS returning 1/0 for true/false from comparisons. So VAR2 is compared to 0,. returning either a 1 or 0. In this case since I do not have a value for VAR2 missing is compared to 0 and returns "not equal" or false, 0. Same for Var3. Var1 = (the result of comparing) 10 and 0 and 0. SAS treats any numeric value other than Missing or 0 as False. So that resolves to Var1 = True and False and False, which is False (true only if all are true) and hence 0.

To assign non-missing values to multiple variables you need each assignment as a single statement. Like this:

data example;
   x=3;
   if x=3 then do;
     var1=0;
     var2=0; 
     var3=0;
   end;
run;

You might be asking why did I use Var1=10? With your code you may have thought that the Likely_ct=0 was correctly assigned and trying to figure out why the rest weren't. In fact, the result of zero for that was the result of a logical comparison.

 

So your counts EXCEPT Likely_ct were not resetting at First.Screen.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 906 views
  • 0 likes
  • 4 in conversation