LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 2008, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 10 Apr 2008 14:44:36 -0700
Reply-To:     "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Subject:      Re: Put macro variable list into a string
Comments: To: SUBSCRIBE SAS-L Dan <deniseyu001@GMAIL.COM>
In-Reply-To:  <200804102111.m3AJq6J7018959@malibu.cc.uga.edu>
Content-Type: text/plain; charset=iso-8859-1

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On > Behalf Of SUBSCRIBE SAS-L Dan > Sent: Thursday, April 10, 2008 2:11 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Put macro variable list into a string > > SasLers: > > Please help: > > data mockdata ; > do i=1 to 10 ; > x=compress('A'||put(i, 8.)) ; > output ; > end ; > run; > > proc sql noprint ; > select distinct x into :testvar separated by ',' > from mockdata; > quit ; > > data _null_ ; > %put Macro variable "Testvar" is >>>&testvar<<<< ; > run; > > > The code generate &testvar as A1,A10,A2,A3,A4,A5,A6,A7,A8,A9 > > However, I want 'A1','A10','A2','A3','A4','A5','A6','A7','A8','A9'. > > Because later I want something like > > if desirevar in ('A1','A10','A2','A3','A4','A5','A6','A7','A8','A9') > > which translate to if if desirevar in (&testvar) >

You have received some workable solutions. Here is one more. The way I usually do this is something like this:

proc sql noprint ; select distinct x into :testvar separated by '","' from mockdata; quit ;

Then you can use the macro variable as follows:

if desirevar in("&testvar");

The double-quotes around the macro variable reference allow the macro variable to be resolved, and at the same time provide the leading quote for the first item in the macro variable and the trailing quote for the last item in the macro variable.

Hope this helpful,

Dan

Daniel J. Nordlund Research and Data Analysis Washington State Department of Social and Health Services Olympia, WA 98504-5204


Back to: Top of message | Previous page | Main SAS-L page