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

Hi:

For tables I ve produced using proc SQL, I'd like to add a row of frequencies at the top of the table.  Do you have suggestions for the best way for me to add this row to the table?

Is there a better way than to: use proc freq, then use data step processing to create a data set with just the row of frequencies I want (since, for example, proc transpose wouldn't seem to be helpful since the proc freq output data set wouldn't be multiple observations per ID/by variable)?

Current Proc SQL table:

ObsVariableestabgroupampestabgroupsstestabgroupnurestabgrouphihFPROBpooledmean
1var1xxxxxxxxxxxxxx
2var2xxxxxxxxxxxxxx
3var3xxxxxxxxxxxxxx

I'd like to add a row of frequencies for estabgroupamp through estabgrouphih

So, used the following:

proc freq data=sample;

table estabgroup /out=freq_estabgroup;

run;

data freq_estabgroup1;

set freq_estabgroup;

variable="N";

if estabgroup="amp" then N_estabgroup_amp=COUNT;

if estabgroup="sst" then N_estabgroup_sst=COUNT;

if estabgroup="hih" then N_estabgroup_hih=COUNT;

if estabgroup="nur" then N_estabgroup_nur=COUNT;

drop estabgroup count percent;

run;

But of course I get:

Is there a better way?

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

You didn't show what your table looked like prior to running proc freq but, given your proc freq output, you could always use something like:

/*create test data*/

data freq_estabgroup;

  input variable $

        N_exemplar_Control

        N_exemplar_CurrentOSHA

        N_exemplar_Dialogue

        N_exemplar_Furture

        N_exemplar_MythFact;

  cards;

N 64608 . . . .

N . 6802 . . .

N . . 6802 . .

N . . . 10285 .

N . . . . 10207

;

data freq_estabgroup1;

  update  freq_estabgroup (obs=1)  freq_estabgroup;

  by variable;

run;

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

You didn't show what your table looked like prior to running proc freq but, given your proc freq output, you could always use something like:

/*create test data*/

data freq_estabgroup;

  input variable $

        N_exemplar_Control

        N_exemplar_CurrentOSHA

        N_exemplar_Dialogue

        N_exemplar_Furture

        N_exemplar_MythFact;

  cards;

N 64608 . . . .

N . 6802 . . .

N . . 6802 . .

N . . . 10285 .

N . . . . 10207

;

data freq_estabgroup1;

  update  freq_estabgroup (obs=1)  freq_estabgroup;

  by variable;

run;

Reeza
Super User

Maisha_Huq wrote:

Is there a better way than to: use proc freq, then use data step processing to create a data set with just the row of frequencies I want (since, for example, proc transpose wouldn't seem to be helpful since the proc freq output data set wouldn't be multiple observations per ID/by variable)?

Did you try a proc transpose?

Maisha_Huq
Quartz | Level 8

Thank you both!  I ended up going with some data step processing

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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