BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Priyamvada07
Obsidian | Level 7

I have the following data

 

DATA HAVE;
input year dz area;
cards;
2000 1 08
2000 1 06
2000 1 06
2001 1 08
2001 1 06
2001 1 06
2002 1 08
2002 1 06
2002 1 06
;
run;

 

I want separate outputs for proc freq dz*area for each year. I can subset data for each year and get the desired table for each year.

data want_2000;

set have;

if year =2000 then output want_2000;

run;

 

proc freq data=want_2000;

table dz*area;

run;

However, I have too many years to subset the data for each. I want to create a loop to subset each each year's data and then may be a loop to do the proc freq for each subset. Is there a way to use 'array' to be able do what I want?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use a BY statement.

 

proc sort data=have;
by year;
run;

proc freq data=have;
by year;
table dz*area;
run;


@Priyamvada07 wrote:

I have the following data

 

DATA HAVE;
input year dz area;
cards;
2000 1 08
2000 1 06
2000 1 06
2001 1 08
2001 1 06
2001 1 06
2002 1 08
2002 1 06
2002 1 06
;
run;

 

I want separate outputs for proc freq dz*area for each year. I can subset data for each year and get the desired table for each year.

data want_2000;

set have;

if year =2000 then output want_2000;

run;

 

proc freq data=want_2000;

table dz*area;

run;

However, I have too many years to subset the data for each. I want to create a loop to subset each each year's data and then may be a loop to do the proc freq for each subset. Is there a way to use 'array' to be able do what I want?

 

 


 

View solution in original post

1 REPLY 1
Reeza
Super User

Use a BY statement.

 

proc sort data=have;
by year;
run;

proc freq data=have;
by year;
table dz*area;
run;


@Priyamvada07 wrote:

I have the following data

 

DATA HAVE;
input year dz area;
cards;
2000 1 08
2000 1 06
2000 1 06
2001 1 08
2001 1 06
2001 1 06
2002 1 08
2002 1 06
2002 1 06
;
run;

 

I want separate outputs for proc freq dz*area for each year. I can subset data for each year and get the desired table for each year.

data want_2000;

set have;

if year =2000 then output want_2000;

run;

 

proc freq data=want_2000;

table dz*area;

run;

However, I have too many years to subset the data for each. I want to create a loop to subset each each year's data and then may be a loop to do the proc freq for each subset. Is there a way to use 'array' to be able do what I want?

 

 


 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

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
  • 1 reply
  • 467 views
  • 1 like
  • 2 in conversation