What do you mean by "name of age"?
And is your question how to re-engineer the sql code in a data step?
First, sort by age. Then use a data step with
retain the new variable agecount, set it to 1 at first.age, and increment it else. At last.age, output.
See examples for the use of by in a data step here: https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=lestmtsref&docsetTarget=p...
Here is a data step equivalent to your PROC SQL code:
/*PROC SQL */ proc sql; create table want as /* <-- add this code if you want to output a dataset */ select age, count(age) as Age_N from sashelp.class group by age; quit; /* DATA STEP EQUIVALENT */ proc sort data=sashelp.class out=class_sorted; by age; run; proc means data=class_sorted n nonobs; var age; class age; ways 1; output out=want (drop=_:) n= /autoname; /* <-- add this code if you want to output a dataset */ run;
All the best,
This isn't a great idea for a data step either, the 'SAS' method to do this would be to use PROC FREQ (or REPORT, TABULATE, MEANS). This provides displayed output or a dataset.
proc freq data=sashelp.class; table age / out = want; run;
proc means data=sashelp.class N; class age; output out=want_means N= ; run;
data dd; set sashelp.class; run; proc sql; select age, count(age) from dd group by age; quit;
i want output in datastep group by age as well as name of age of agecount
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.