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

I'm using ODA, trying to create a variable with this code - 

 

libname adeno '/home/u58566978/adeno';
data work.adeno1;
set adeno.finch_gjred;
run;

data work.adeno1;
set adeno.finch_gjred;
if beertotl=2 and beerfrq2=0 and beerfrqx2=0 and beernum2=98 then wrong=0;
if beertotl=3 and beerfrq3=0 and beerfrqx3=0 and beernum3=98 then wrong=0;
if beertotl=4 and beerfrq4=0 and beerfrqx4=0 and beernum4=98 then wrong=0;
if beertotl=5 and beerfrq5=0 and beerfrqx5=0 and beernum5=98 then wrong=0;
if beertotl=6 and beerfrq6=0 and beerfrqx6=0 and beernum6=98 then wrong=0;
if beertotl=7 and beerfrq7=0 and beerfrqx7=0 and beernum7=98 then wrong=0;
if beertotl=8 and beerfrq8=0 and beerfrqx8=0 and beernum8=98 then wrong=0;
if beertotl=9 and beerfrq9=0 and beerfrqx9=0 and beernum9=98 then wrong=0;
if beertotl=10 and beerfrq10=0 and beerfrqx10=0 and beernum10=98 then wrong=0;
if beertotl=11 and beerfrq11=0 and beerfrqx11=0 and beernum11=98 then wrong=0;
if beertotl=12 and beerfrq12=0 and beerfrqx12=0 and beernum12=98 then wrong=0;
else wrong=1;
run;

proc freq data=work.adeno1;
tables wrong;
run;

 

....but when I do that, this is the table I get. Screen Shot 2021-06-29 at 1.56.49 PM.pngWhen I exclude the 'else wrong=1' line, I get this, which is what I want, but I need to have a "1=832" line instead of those people being considered missing. Is this an ordering problem in my code? Any help is much appreciated. 

 

Screen Shot 2021-06-29 at 1.58.43 PM.png

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Your ELSE is not correct. Try this:

 

libname adeno '/home/u58566978/adeno';
/*These next three lines not relevant to this problem, so I have commented them out */
/*data work.adeno1;*/
/*set adeno.finch_gjred;*/
/*run;*/

data work.adeno1;
    set adeno.finch_gjred;
    if beertotl=2 and beerfrq2=0 and beerfrqx2=0 and beernum2=98 then wrong=0;
    else if beertotl=3 and beerfrq3=0 and beerfrqx3=0 and beernum3=98 then wrong=0;
    else if beertotl=4 and beerfrq4=0 and beerfrqx4=0 and beernum4=98 then wrong=0;
    else if beertotl=5 and beerfrq5=0 and beerfrqx5=0 and beernum5=98 then wrong=0;
    else if beertotl=6 and beerfrq6=0 and beerfrqx6=0 and beernum6=98 then wrong=0;
    else if beertotl=7 and beerfrq7=0 and beerfrqx7=0 and beernum7=98 then wrong=0;
    else if beertotl=8 and beerfrq8=0 and beerfrqx8=0 and beernum8=98 then wrong=0;
    else if beertotl=9 and beerfrq9=0 and beerfrqx9=0 and beernum9=98 then wrong=0;
    else if beertotl=10 and beerfrq10=0 and beerfrqx10=0 and beernum10=98 then wrong=0;
    else if beertotl=11 and beerfrq11=0 and beerfrqx11=0 and beernum11=98 then wrong=0;
    else if beertotl=12 and beerfrq12=0 and beerfrqx12=0 and beernum12=98 then wrong=0;
    else wrong=1;
run;

proc freq data=work.adeno1;
    tables wrong;
run;

You might also benefit from properly indenting your code, as I have done above.

--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26

Your ELSE is not correct. Try this:

 

libname adeno '/home/u58566978/adeno';
/*These next three lines not relevant to this problem, so I have commented them out */
/*data work.adeno1;*/
/*set adeno.finch_gjred;*/
/*run;*/

data work.adeno1;
    set adeno.finch_gjred;
    if beertotl=2 and beerfrq2=0 and beerfrqx2=0 and beernum2=98 then wrong=0;
    else if beertotl=3 and beerfrq3=0 and beerfrqx3=0 and beernum3=98 then wrong=0;
    else if beertotl=4 and beerfrq4=0 and beerfrqx4=0 and beernum4=98 then wrong=0;
    else if beertotl=5 and beerfrq5=0 and beerfrqx5=0 and beernum5=98 then wrong=0;
    else if beertotl=6 and beerfrq6=0 and beerfrqx6=0 and beernum6=98 then wrong=0;
    else if beertotl=7 and beerfrq7=0 and beerfrqx7=0 and beernum7=98 then wrong=0;
    else if beertotl=8 and beerfrq8=0 and beerfrqx8=0 and beernum8=98 then wrong=0;
    else if beertotl=9 and beerfrq9=0 and beerfrqx9=0 and beernum9=98 then wrong=0;
    else if beertotl=10 and beerfrq10=0 and beerfrqx10=0 and beernum10=98 then wrong=0;
    else if beertotl=11 and beerfrq11=0 and beerfrqx11=0 and beernum11=98 then wrong=0;
    else if beertotl=12 and beerfrq12=0 and beerfrqx12=0 and beernum12=98 then wrong=0;
    else wrong=1;
run;

proc freq data=work.adeno1;
    tables wrong;
run;

You might also benefit from properly indenting your code, as I have done above.

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1 reply
  • 452 views
  • 1 like
  • 2 in conversation