I have this data set and I want to get the number of days with a number of deaths equal or higher to 1 by iso_code:
DATA MYLIB_D3.NB_DECES;
SET MYLIB_D3.COVID_DATA;
BY date iso_code;
WHERE new_deaths>=1;
RUN;
PROC FREQ data= mylib_d3.nb_deces ;
TABLE date*pays;
RUN;
As stated in your other thread, do not post data as attachments. Post data following these instructions (and not in any other form).
proc sql;
create table MYLIB_D3.NB_DECES as
select date, iso_code, count(*) as NbyDate FROM MYLIB_D3.COVID_DATA WHERE new_deaths>=1 GROUP BY date, iso_code;
quit;
i should say, this will give you a count of how many per day where new>1. from that, you can get a count of the number of those days there are.
I won't bother with the data you posted as an attachment, but this is a good situation for running a proc freq on a subset of the original data, and then running a proc freq and the results of the first proc freq:
proc freq data=myhlib_d3.nb_deces noprint;
where new_deaths>=1;
table date*iso_code / out=need (keep=iso_code date);
run;
proc freq data=need;
tables iso_code /out=want (keep=iso_code count);
run;
Note that the WHERE filter can be applied in the first proc freq, so you don't need to run a preparatory DATA step.
The first proc freq writes an output dataset NEED. It would ordinarily have 4 variables: iso_code date count and percent. But you only need the iso_code and date variables.
Then the second proc freq is applied to dataset need, giving a frequency of each iso_code, i.e. then number of unique date values encountered per iso_code.
This is a good example of using the power of various proc's instead of data step programming.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.