hi all,
i am aware little how first.var and last.var works but i want to assign value to all the var that are not in first.var and last.var but not able.
your help would be appreciated.
Thank you,
data need;
format this;
set have;
by sex;
if first.sex then do;
this='first';
end;
if not
first.sex and last.sex then do;
this='in_betwn';
end;
if last.sex then do;
this='last';
end;
/* */
/* if UPCASE(sex) NE ('F') THEN DO; */
/* YY='ZZ'; */
/* END; */
run;
Keep it simple
data need;
set have; by sex;
length this $8;
if first.sex then this='first';
else if last.sex then this='last';
else this='in_betwn';
run;
Two easy issues here ...
First, you need to set a length for your new variable. Otherwise it takes its length from "first" and won't be long enough to hold "in_betwn":
length this $ 8;
Second, NOT applies to just one condition. To get it to apply to both, add parentheses:
if not
(first.sex or last.sex) then do;
if not first.sex and not last.sex then do;
this='in_betwn';
end;
I get a "not valid file type" error attempting to open your pdf.
If the "problem" is that in between values are showing as "in_be" then the issue is that you did not assign a length to the THIS variable and so SAS assigned a length of 5 because the first use of the variable is in: This='first'; and "first" is 5 characters long.
If "this" variable exists in your set Have data set and it has a length other than 5, or is numeric that could cause other issues.
If there is something else then show the results as text and likely show the log from running the code as well.
Keep it simple
data need;
set have; by sex;
length this $8;
if first.sex then this='first';
else if last.sex then this='last';
else this='in_betwn';
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: