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

Hello,

I was trying to run this code:

Data HW4set;
set mylib.HW4;
if 1 = p1p then correct = correct+1;
If 1 = p2p then correct = correct+1;
run;

But when I run it I get a variable of missing values.

Diana___0-1601305203771.png

How do you make a variable dependent on whether the value is 1 or 2(true/false)?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Your variable named CORRECT is not given a starting value, in other words, it is missing. So when you add 1 to missing, you get missing. You could re-write the code like this to eliminate the problem.

 

Data HW4set;
set mylib.HW4;
if 1 = p1p then correct = sum(correct,1);
If 1 = p2p then correct =sum(correct,1);
run;

OR

 

Data HW4set;
set mylib.HW4;
correct=0;
if 1 = p1p then correct = correct+1;
If 1 = p2p then correct = correct+1;
run;
--
Paige Miller

View solution in original post

3 REPLIES 3
Diana__
Fluorite | Level 6

*Whether the value is correct/incorrect.

*the p1p and p2p variables are at the beginning of the document, the correct variable is the 32nd variable.

PaigeMiller
Diamond | Level 26

Your variable named CORRECT is not given a starting value, in other words, it is missing. So when you add 1 to missing, you get missing. You could re-write the code like this to eliminate the problem.

 

Data HW4set;
set mylib.HW4;
if 1 = p1p then correct = sum(correct,1);
If 1 = p2p then correct =sum(correct,1);
run;

OR

 

Data HW4set;
set mylib.HW4;
correct=0;
if 1 = p1p then correct = correct+1;
If 1 = p2p then correct = correct+1;
run;
--
Paige Miller
Diana__
Fluorite | Level 6

Thank you so much for your help!

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!

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
  • 3 replies
  • 363 views
  • 1 like
  • 2 in conversation