Hello,
If I have two variables called xvar and yvar, how can I generate the yvar by adding 1 if xvar is even and staying the same if xvar is odd? The yvar is initialized to be 1.
xvar yvar
2 1
3
5
6
7
8
Output wanted:
xvar yvar
2 1
3 1
5 1
6 2
7 2
8 3
I tried the retain statement for yvar but can't get the expected result. Thanks.
data have;
input xvar;
retain yvar 0;
if mod(xvar,2)=0 then yvar+1;
cards;
2
3
5
6
7
8
;
run;
data have;
input xvar;
retain yvar 0;
if mod(xvar,2)=0 then yvar+1;
cards;
2
3
5
6
7
8
;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.