BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

Are you counting the number of companies, by fiscal year, for each famafrench classification?   If so, and if you have exactly one record per company per year, then you can do a proc freq, as in:

 

proc freq data=test;
  tables fyear * famafrench /out=annual_ff_freqs (drop=percent);
run;

This will print a tabulation that looks like your table, and output a data set, with one record per cell, containing variables FYEAR, FAMAFRENCH, and COUNT.  

 

Now, if you want a data set that looks like your table (one obs per year, and one var per ff), then apply proc transpose to the proc freq output:

 

proc transpose data=annual_ff_freqs out=want (drop=_name_ _label_);
  by fyear;
  id famafrench;
  var count;
run;
--------------------------
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

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

View solution in original post

5 REPLIES 5
Reeza
Super User
Is that sample table your input data? Please show clearly, what your input data looks like and preferably, the exact matching output you'd expect.
bobbystweart12
Calcite | Level 5

The table would be the preferred output.

 

The actual input is millions of lines but simply it is a year and then a number 1 - 12.  I put a very small excerpt from it below

 

YearFamafrench
20181
20191
20201
20183
20193
20203
20185
20195
20205
20185
20195
20205
20186
20196
20206
20187
20197
20207
mkeintz
PROC Star

Are you counting the number of companies, by fiscal year, for each famafrench classification?   If so, and if you have exactly one record per company per year, then you can do a proc freq, as in:

 

proc freq data=test;
  tables fyear * famafrench /out=annual_ff_freqs (drop=percent);
run;

This will print a tabulation that looks like your table, and output a data set, with one record per cell, containing variables FYEAR, FAMAFRENCH, and COUNT.  

 

Now, if you want a data set that looks like your table (one obs per year, and one var per ff), then apply proc transpose to the proc freq output:

 

proc transpose data=annual_ff_freqs out=want (drop=_name_ _label_);
  by fyear;
  id famafrench;
  var count;
run;
--------------------------
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

--------------------------
bobbystweart12
Calcite | Level 5

Thank you the second one worked perfectly. Is there a way to do the same if famafrench was instead a string?

mkeintz
PROC Star

Proc freq treats all variables as nominal variables, so they can be numeric or character.

 

But more in the spirit of learning to use a software product for a project, this is exactly the kind of question that begs to be answered by trial - which would be rewarded with success in this case.

--------------------------
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!

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
  • 5 replies
  • 610 views
  • 5 likes
  • 3 in conversation