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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 487 views
  • 0 likes
  • 3 in conversation