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

I am formatting data using proc tabulate for when I call the data in proc report.  I need to know the name of the columns from proc tabulate to reference them in proc report.  This works until I add in the sum feature in proc tabulate.  I’m not sure what my variable is called after I add in the sum feature. In this particular scenario the summed variable is students_enrolled_sum.  However if I change out the location column with a marco &columnName identifying the column name gets tricky.  Without the sum my column name is always n.  I tried using labels however the label appears to only be a label and not a name as can be seen in a proc print statement like the print screen.

proc tabulate data=enrollment missing out=enrollment4 FORMAT=COMMA8.;

  class location academic_period;

  var students_enrolled;

  table sum*location='n'*students_enrolled='' sum*students_enrolled=' '*all, academic_period /row=float;

  keylabel sum=' ' n=' ';

run;

proc print data=enrollment4;

tabulate_n.png

1 ACCEPTED SOLUTION

Accepted Solutions
DavidPhillips2
Rhodochrosite | Level 12

I used the concatenate function to combined

location || sum to reference my variables dynamically. This works for me there should be a better way like being able to reference the label name.

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Can you not query the SASHELP.VCOLUMN (DICTIONARY.COLUMNS) information, if _sum is always the suffix then:

proc sql;

     select     NAME

     into         :THE_SUM_VAR

     from       DICTIONARY.COLUMNS

     where      LIBNAME="WORK" and MEMNAME="ABC";

quit;

Then use the macro variable.  If _sum isn't the suffix always, take a list of your variables before and after and remove the before from the after to be left with additional variables.

DavidPhillips2
Rhodochrosite | Level 12

I used the concatenate function to combined

location || sum to reference my variables dynamically. This works for me there should be a better way like being able to reference the label name.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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