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

Hi,

 

I am trying to create a macro that hold all avisit values, that way i don't have to manual check the data if there's new visits in the future.

 

 

Here is my starting point, getting all avisitn values in adlb then using avisitn values to create a table shell/dummy dataset "&avisitn".

 

proc sort data=adlb out=shell_ (keep=avisitn) nodupkey;
by avisitn;
run;


data shell;
   set shell_;
	  do ord1= &avisitn;  /*avisitn values go here*/
	  output;
	  end;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
smantha
Lapis Lazuli | Level 10

Your question is not very clear. If you want a list of all unique values as a single macro variable you can use

proc sql;
select distinct avisitn into: avisitn separated by ',' from adlb;
quit;
%put &avisitn;

if you are doing the way you want

data _null_;
length avisitn_string $32767.;
set shell_ end=last;
retain avisitn_string '';
 avisitn_string = strip( avisitn_string)||','||strip(put(avisitn,$5.));
if last then call symputx('avisitn',avisitn_string);
run;
%put &avisitn.;

View solution in original post

2 REPLIES 2
smantha
Lapis Lazuli | Level 10

Your question is not very clear. If you want a list of all unique values as a single macro variable you can use

proc sql;
select distinct avisitn into: avisitn separated by ',' from adlb;
quit;
%put &avisitn;

if you are doing the way you want

data _null_;
length avisitn_string $32767.;
set shell_ end=last;
retain avisitn_string '';
 avisitn_string = strip( avisitn_string)||','||strip(put(avisitn,$5.));
if last then call symputx('avisitn',avisitn_string);
run;
%put &avisitn.;
ChrisNZ
Tourmaline | Level 20

>create a table shell/dummy dataset "&avisitn".

Do you want to create one data set by visit?

I can't think of a reason where this could ever be justified.

What's the purpose?

Anyway, if that variable is numeric, this does what you seem to be asking:

proc sql noprint;
  select distinct AVISITN into: avisitn separated by ',' from ADLB order by AVISITN;
quit;
%put &=avisitn;

data X;
  do ORD1= &avisitn.;  /*avisitn values go here*/
	  /* Some code */
  end;
run;

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 844 views
  • 0 likes
  • 3 in conversation