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

I am a little out of practice, I'd like to macro the following code so it will go through each unique 'pcpid' seperatley (from 1 %to end?) and put the pcpid on the graph as a label.  I'm thinking a simple macro loop with symputx to macro the variable through the loop but I don't know how to do it.  Any help will be appreciated:

title "PCPID = &pcpid";

proc gplot data=test;

symbol i=join v=circle h=2;

plot distance*month;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why not just use a BY statement?

options nobyline;

title "PCPID = #byval(pcpid)";

proc gplot data=test;

by pcpid ;

symbol i=join v=circle h=2;

plot distance*month;

run;

View solution in original post

4 REPLIES 4
Steelers_In_DC
Barite | Level 11

or is this a situation for a symputx and symgetn?

Tom
Super User Tom
Super User

Why not just use a BY statement?

options nobyline;

title "PCPID = #byval(pcpid)";

proc gplot data=test;

by pcpid ;

symbol i=join v=circle h=2;

plot distance*month;

run;

Steelers_In_DC
Barite | Level 11

Awesome suggestion.  I'll have to read up on this option as it is new to me.  This did exactly what I wanted.

Thanks!

Tom
Super User Tom
Super User

There are a number of writeups for how to do something like that. You might start with this one.

http://www.sascommunity.org/wiki/List_Processing_Basics_Creating_and_Using_Lists_of_Macro_Variables

Personally for really simple problems I normally create a single macro variable with a space delimited list of values using PROC SQL and remember the number of values by saving the value of the automatic macro variable SQLOBS.

proc sql noprint;

  select name into :names separated by ' '

  from sashelp.class;

%let n=&sqlobs;

quit;

%do i=1 %to &n ;

   %let name=%scan(&names,&i,%str( ));

.... &name ....

%end;

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
  • 4 replies
  • 448 views
  • 0 likes
  • 2 in conversation