BookmarkSubscribeRSS Feed
Stephenjohn
Calcite | Level 5

Hello, 

Below is the macro variable list , how can we read these values one at a time from this macro variable..

 

%put &list;
AE AE AEMDSAML AEMDSAML AEMDSAML AEMDSAML AEPNEU AEPNEU AEPNEU AEPNEU AESPM AESPM AESPM C19ASMT CM CNCRTX CNCRTX CNCRTX
CNCRTX_1 CNCRTX_1 CNCRTX_1 CP CP CR CVEVT_ARRH_CR CVEVT_ARRH_CR CVEVT_ARRH_CR CVEVT_ARRH_CR CVEVT_ARRH_CR CVEVT_ARRH_CR
CVEVT_CHF_CR CVEVT_CHF_CR CVEVT_CHF_CR CVEVT_CHF_CR CVEVT_CHF_CR CVEVT_CHF_CR CVEVT_CHF_CR CVEVT_CHF_CR CVEVT_CVATIA_CR
CVEVT_CVATIA_CR CVEVT_CVATIA_CR CVEVT_CVATIA_CR CVEVT_DEATH_CR CVEVT_DEATH_CR CVEVT_DVT_CR CVEVT_DVT_CR CVEVT_DVT_CR
CVEVT_DVT_CR CVEVT_DVT_CR CVEVT_DVT_CR CVEVT_DVT_CR CVEVT_MYOINF_CR CVEVT_MYOINF_CR CVEVT_MYOINF_CR CVEVT_MYOINF_CR
CVEVT_MYOINF_CR CVEVT_MYOINF_CR CVEVT_MYOINF_CR CVEVT_MYOINF_CR CVEVT_PAT_CR CVEVT_PAT_CR CVEVT_PAT_CR CVEVT_PAT_CR
CVEVT_PULHYP_CR CVEVT_PULHYP_CR CVEVT_PULHYP_CR CVEVT_PULHYP_CR CVEVT_REVAS_CR CVEVT_REVAS_CR CVEVT_VALV_CR
CVEVT_VALV_CR CVEVT_VALV_CR CVEVT_VALV_CR CVEVT_VALV_CR CVEVT_VALV_CR DA DEATH DEATH DM DM DM DS EOTN EOTN EOTT EVAL EX
EX_15 EX_IV EX_IV FD FUACT FUACT HVT ICF_WITH IE IE INDTX INDTX INF_CONSENT INF_CONSENT LBIOPSY_CR LBIOPSY_CR_1 LB_CHEM
LB_COAG LB_HEMA LB_LIPID LB_URIN LEREPORT_CR LEREPORT_CR LIMAGING_CR MEDHIST_A_LIVER_CR MH NESCREEN NSCLCHIS NSCLCHIS
NSCLCHIS NTM OH PHEM PK_LIVER_PKSMPID PR PR_FCR PR_IMG PV QS RAND RUCAM_CR SAE SI SUBUSE_AL_LIVER_CR SURVSTAT TLSUM TSH
TUNL TUNL TUNT2 TUNT2 TUTG2 TUTG2 UNSCH UPT VS VS_1

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Inside a macro

 

%do i=1 %to %sysfunc(countw(&list));
    %let thisvar = %scan(&list,&i,%str( ));
    /* Do some action with &thisvar */
%end;
--
Paige Miller
ballardw
Super User

I think that you may seriously want to consider just how you are building that list of variables and what you expect to do with it. You have repeats of the same value such as

CVEVT_ARRH_CR CVEVT_ARRH_CR CVEVT_ARRH_CR CVEVT_ARRH_CR CVEVT_ARRH_CR CVEVT_ARRH_CR

which means that you will likely repeat the same thing 5 times for that value. Which means a likely waste of clock cycles.

There are several of these repeated values, so even more wasted clock cycles.

OR you are going to have to provide more information somewhere if each of those repeats is to be treated differently. Which means that @PaigeMiller's concise solution may be insufficient in the real task.

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