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 (June 2008, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 9 Jun 2008 12:08:40 -0400
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: Macro 2

..and a few answers to your questions, before making it better: _n_ is the automatic loop-counter of a DATA-step. It tells you, how often did that loop iterate. If there is nothing special in the step, that could also used as a kind of counter of the obs.

The complicated CALL SYMPUT:

in the pre-V9 days of SAS, you often had the problem, that you wanted to store something like ' this is a text ' in a macro variable. That thing you might use in a TITLE:

TITLE "ABC, &text you should read";

That came out as

ABC, this is a text you should read

That doesn't look nice. You want it left aligned:

call symput("text",left(text));



ABC, this is a text you should read

also not nice, so you want to get rid of the right blanks:

call symput("text",trim(left(text)));

by the way: text=trim(left(text)); call symput("text",text);

makes it more readable, but not better: the trailing blanks come from the length of the variable text, which is not changed with a function call.

Because that things above is a standard problem, which occures very often, the SAS developers created that nice new functions.

Another nice feature: if you converted numbers with put, they were always right aligned, what is sometimes not ok. You can use

put(num,8. -L)

to left align the result instead of


If you are concatenating the result, also a "standard", CATS is the best way for sure. I can say: I like cats very much (ok, not all of them, some are too big for me, e.g. those with the yellow and black stripes...)

Last one (I hope I've it all?)

%let combo=;

is the assignement of "nothing" to &combo. A "initialization" if you want. It has not yet a value, but it is defined and you'll get no error like "symbol not resolved" if you use it like:

%put &combo;


On Mon, 9 Jun 2008 11:37:34 -0400, Long, Stuart (NIH/NIEHS) [C] <long3@NIEHS.NIH.GOV> wrote:

>Hi Carol: > > You are using code that is designed for Pre SAS V9. Here is how >you could rewrite the code to take advantage of the features of SAS V9: > >DATA names; > SET names0 END=last; > fact_num=_N_; > CALL SYMPUTX(CATS('factor',_N_),factor); > IF last THEN CALL SYMPUTX('tot_fact',_N_); >RUN; > >Some notes on this code: > >1) CALL SYMPUTX (new to V9) automatically trims leading and trailing >blanks from the second argument. I would recommend that you always use >CALL SYMPUTX unless you specifically know that you have a reason to use >CALL SYMPUT. For the most part, CALL SYMPUTX makes CALL SYMPUT >obsolete. > >2) CATS is a more efficient method of concatenating character strings >with other character strings or numeric values. Like SYMPUTX, it >automatically removes leading and trailing blanks from the second >argument. In addition, it automatically makes the numeric to character >conversion if you are building a character string by concatenating a >character value with a numeric value. > >3) It appears you have some mistakes in your code. > A) fact_num is bogus since is being coded, but not used for anything. >Take it out. > B) in your first CALL SYMPUT, you are concatenating "n" when you >should be concatenating "_N_". > >4) Always remember to place a RUN; statement after each DATA Step, >unless you have a specific reason that you want to omit it. > > >I hope you find these suggestions helpful. > >Stu > > > >-----Original Message----- >From: Carol [mailto:caroline5658@YAHOO.COM] >Sent: Friday, June 06, 2008 6:01 PM >To: SAS-L@LISTSERV.UGA.EDU >Subject: Macro 2 > > >There're some questions about Macro: > >data names; > set names0 end=last; > fact_num=_n_; > call symput('facor'II left(_n_), trim(left(factor))); > if last then call symput('tot_fact',trim(left(_n_))); > >%let combo=; >%restack; > >I'm getting trouble in understanding of 1. what is fact_num=_n_; ? > 2. CALL SYMPUT >means that creates the macro variable, so code of call symput('facor'II >left(_n_), trim(left(factor))); does mean that macro variable of FACTOR >was created and then trim it? > 3. Got empty >feeling about code of "if last then call >symput('tot_fact',trim(left(_n_)));", what that exactly mean? > 4. %let >combo=; %restack; what's value of combo? Is that restack? > >Many Thanks!

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