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. When 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.
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.
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.