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 (February 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 26 Feb 2008 09:13:27 -0500
Reply-To:     Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject:      Re: Passing variables from data step to macro while avoiding
              loops. Is it possible?

Howard, yes, I'm confused: "...to avoid a program that doesn't need loops...". I'm german and my english isn't good. If I understand that right, that means " I don't want programs without loops..." or in simpler words "...I want only programs with loops". Ok, but I think we now have all possible scenarios... Thanks, Gerhard

On Tue, 26 Feb 2008 08:56:37 -0500, Howard Schreier <hs AT dc-sug DOT org> <schreier.junk.mail@GMAIL.COM> wrote:

>On Tue, 26 Feb 2008 03:11:13 -0500, Gerhard Hellriegel ><gerhard.hellriegel@T-ONLINE.DE> wrote: > >>Without reading it all. An example to bring all "ages" of SASHELP.CLASS to >>macro variables: >> >>%let no=0; /* dont forget that if the dataset might be empty! */ >>data _null_; >> set sashelp.class; >> call symput("no",_n_); /* you need the number */ >> call symput("age"!!put(_n_,8. -L),age); >>run; >> >>What can you do with that? >> >>%macro doit; >> %do i=1 %to &no; >> %put &&age&i = AGE &i; >> %end; >>%mend; >>%doit; >> >>If you use such a %do loop in a DATA step, you can avoid e.g. a loop, >>instead you generate all the 19 lines-of-code. Sometimes that might be >>faster. >>Gerhard >> > >I think Naveen wanted to *avoid* this sort of thing (macro loops and >constellations of macro variables) and instead have the automatic looping of >the DATA step drive things. Then Toby's pointer to CALL EXECUTE is the right >direction. > >> >>On Mon, 25 Feb 2008 20:48:26 -0500, Nancy Brucken <brucken@PROVIDE.NET> >>wrote: >> >>>Hi, >>> >>>In addition to Ron's suggestion to move the RUN; statement after your CALL >>>SYMPUT, you also need to modify your CALL SYMPUT statement if you want to >>>store all 20 of your values in separate macro variables &STK1-&STK20. As >>>your code stands right now, every time SAS reads in another observation, >>>the value of SYMBOL on that record is stored in &STK. Thus, the values >>>keep overwriting each other, until on the 20th time through, &STK = the >>>value of SYMBOL on your 20th record. >>> >>>If you want to store all of the values of SYMBOL in separate macro >>>variables, change your CALL SYMPUT statement to read: >>> >>>call symput("stk" || trim(left(put(_n_, 2.))), put(symbol, $10.)); >>> >>>If you're running SAS 9, you can use one of the CAT functions to do the >>>concatenation (but I'm still stuck in the version 8 world for now, so have >>>to live with that syntax). >>> >>>Hope this helps, >>> Nancy >>> >>>Nancy Brucken >>>brucken@provide.net >>> >>> >>>On Mon, 25 Feb 2008 14:55:13 -0500, Fehd, Ronald J. (CDC/CCHIS/NCPHI) >>><rjf2@CDC.GOV> wrote: >>> >>>>yes, as Toby said you need call execute >>>> >>>>Here are some examples that call parameterized include files: >>>> >>>>http://www.sascommunity.org/wiki/Summarize_Memnames_in_Libname >>>> >>>>the reason that you get the error: >>>> >>>>> WARNING: Apparent symbolic reference STK not resolved. >>>> >>>>is because you do not have a run after your call symput: >>>> >>>>> call symput("stk", put(symbol, $10.)); *Creates the global variable >>>>> "stk" with whatever is in the PDV for symbol. I think???; >>>> >>>>*>>>--->; run; *<---<<<; >>>> >>>>> %quotes (symbol=&stk, start=11/1/45, end = 11/1/09); *Macro that >>>>> created a separate datasets based on the argument supplied for >>>>> "symbol="; >>>> >>>>if your macro does not have complexity, >>>>then reduce it to a parameterized include file >>>>and call execute will handle it for you. >>>> >>>>Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov >>>> >>>> >>>>> -----Original Message----- >>>>> From: owner-sas-l@listserv.uga.edu >>>>> [mailto:owner-sas-l@listserv.uga.edu] On Behalf Of NMani >>>>> Sent: Monday, February 25, 2008 1:14 PM >>>>> To: sas-l@uga.edu >>>>> Subject: Passing variables from data step to macro while >>>>> avoiding loops. Is it possible? >>>>> >>>>> Dear SAS Experts; >>>>> >>>>> (1) I'm very confused. I thought I could exploit the data step to >>>>> avoid creating a program that doesn't need loops but I'm having >>>>> trouble understanding how to pass variable from the data step to the >>>>> macro within the data step itself. If I take the macro outside the >>>>> data step, the program will work but only for the 20th symbol the >>>>> "test1" dataset. I think the problem might be that the PDV initializes >>>>> null and that's messing up the program. I don't really know though. >>>>> Can someone offer me an idea on what's happening in the >>>>> background and/ >>>>> or any suggestions on making this program work. >>>>> >>>>> (2) If my program runs into a symbol and returns an error >>>>> message(usually if the symbol cannot be found on yahoo's database) >>>>> then it stops. For those Visual Basic programmers there's a line of >>>>> code, "One Error Resume Next" that forces the program to continue even >>>>> if an error is generated. Is there a SAS equivalent? >>>>> >>>>> Sincerely, >>>>> >>>>> A student preparing for his base sas certification >>>>> >>>>> >>>>> -------------------------------------------------------------- >>>>> -------------------------------------------------- >>>>> CODE: >>>>> >>>>> data blah; *Random name, should be _null_ but keeping it blah for >>>>> testing reasons; >>>>> >>>>> set test1(obs=20); *Contains the dataset with the ticker names under >>>>> the variable name "symbol"; >>>>> >>>>> call symput("stk", put(symbol, $10.)); *Creates the global variable >>>>> "stk" with whatever is in the PDV for symbol. I think???; >>>>> >>>>> %quotes (symbol=&stk, start=11/1/45, end = 11/1/09); *Macro that >>>>> created a separate datasets based on the argument supplied for >>>>> "symbol="; >>>>> >>>>> run; >>>>> >>>>> >>>>> LOG: >>>>> 127 data blah; >>>>> 128 set test1(obs=20); >>>>> 129 >>>>> 130 call symput("stk", put(symbol, $10.)); >>>>> 131 %quotes (symbol=&stk, start=11/1/45, end = 11/1/09); >>>>> WARNING: Apparent symbolic reference STK not resolved. >>>> >>>>> http://table.finance.yahoo.com:80/table.csv?s=&STK&a=10&b=1&c= >>>>> 1945&d=10&e=1&f=2009&g=d >>>>> WARNING: Apparent symbolic reference STK not resolved. >>>>> WARNING: Apparent symbolic reference STK not resolved. >>>>> >>>>> NOTE: There were 20 observations read from the data set WORK.TEST1. >>>>> NOTE: The data set WORK.BLAH has 20 observations and 5 variables. >>>>> NOTE: DATA statement used (Total process time): >>>>> real time 0.05 seconds >>>>> cpu time 0.03 seconds >>>>> >>>>> >>>>> NOTE: Line generated by the macro variable "SYMBOL". >>>>> 1 &STK >>>>> - >>>>> 22 >>>>> --- >>>>> 202 >>>>> >>>>> ERROR 22-322: Syntax error, expecting one of the following: a name, a >>>>> quoted string, /, ;, _DATA_, >>>>> _LAST_, _NULL_. >>>>> >>>>> ERROR 202-322: The option or parameter is not recognized and will be >>>>> ignored. >>>>> >>>>> NOTE: The SAS System stopped processing this step because of errors. >>>>> WARNING: The data set WORK.STK may be incomplete. When this step was >>>>> stopped there were 0 >>>>> observations and 7 variables. >>>>> NOTE: DATA statement used (Total process time): >>>>> real time 0.02 seconds >>>>> cpu time 0.03 seconds >>>>> >>>>> >>>>> 132 run; >>>>> >>>>>


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