BookmarkSubscribeRSS Feed
Feksan
Fluorite | Level 6

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;

4 REPLIES 4
PaigeMiller
Diamond | Level 26

As stated in your other thread, do not post data as attachments. Post data following these instructions (and not in any other form).

--
Paige Miller
utrocketeng
Quartz | Level 8
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;
utrocketeng
Quartz | Level 8

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.

mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1010 views
  • 4 likes
  • 4 in conversation