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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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