Hi all,
For instance a dataset is sorted by variable X.
How in one iteration reveal if an observation is only one in a group:
if first.X and last.X ...
Thank you!
Thats it you have it.
data want; set have; by x; if first.x and last.x then only_one="Yes"; else only_one="No"; run;
Thats it you have it.
data want; set have; by x; if first.x and last.x then only_one="Yes"; else only_one="No"; run;
No probs, it likely not be the first or last tough day!
Hi,
If you sort a data set and in a data step when you specify by variable then sas creates two automatic variables back end they are first.by variable and last.by variable.
first.by variable value is=1 for the first observation in a dataset and rest of all the by group will be =0 except last.by variable. that will be one
You can observe it by writing example
proc sort data=ds;
by sex;
run;
data ds;
set sashelp.classfit;
by sex;
put _all_;'
if first.sex and last.x then flag=1;
else flag=0;
run;
Thanks
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.