Hello team
why don't I get a group by this code?
data test1; input id sys dia; datalines; 1 23 24 1 23 24 2 12 13 ; Run;
data grouping;
set test1;
by id sys dia;
run;
Am I not supposed to get only for rows for 1 23 24? Please advise me.
Regards,
Blueblue
If you want to reduce the data to one observation per BY group you could use the NODUPKEY option on PROC SORT.
But if the goal is to sort by ID SYS DIA and then reduce it to one observation per value of ID then you can get the FIRST.ID automatic flag that the BY statement creates.
proc sort data=have ;
by id sys dia ;
run;
data min_blood_pressure;
set have;
by id sys dia;
if first.id;
run;
I don't get your question: "Am I not supposed to get only for rows for 1 23 24?", but if I were you I would start by reading the documentation:
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/n1ecf3exv3sn7bn1htxoz074c72z.htm
Bart
What do you mean by "group" here? This is not really a word that describes any SAS structure that I know of.
You are creating GROUPING as a copy of TEST1.
The only thing the BY statement will do in that data step is insure that TEST1 is actually sorted by ID SYS DIA. It for example an observation with ID=1 came after on observation with ID=2 it would generate an error since the that is not the sort order you told the BY statement to expect.
Hello all,
What I mean is to receive one observation for those rows that are same if those observations are sorted properly. I don't know what word I need to use instead of grouping. I know in SAS before grouping, I need to sort my data.
Thanks,
blueblue
If you want to reduce the data to one observation per BY group you could use the NODUPKEY option on PROC SORT.
But if the goal is to sort by ID SYS DIA and then reduce it to one observation per value of ID then you can get the FIRST.ID automatic flag that the BY statement creates.
proc sort data=have ;
by id sys dia ;
run;
data min_blood_pressure;
set have;
by id sys dia;
if first.id;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.