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 (September 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 18 Sep 2006 20:52:37 -0400
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject:      Re: Is there any difference in way macro created ??

On Mon, 18 Sep 2006 14:49:40 -0500, SAS_learner <proccontents@GMAIL.COM> wrote:

>hello guys , I am generating a macro

No macro code in sight. You are using global macro variables, but those are not the same as macro code.

>like this to used for caliculating >percentages

There are less roundabout and simpler ways to get there.

>like this > > proc freq data=V_AE noprint; > tables TREAT_R / missing out=freq0(keep=TREAT_R COUNT); > run; > >proc sql noprint; >create table total as >select sum(count) as total >from freq0 >where treat_r ^= ' ' ; > >quit; >data _null_; > set total; >call symput("tot1",put(total,3.));

You are using PUT to explicitly convert TOTAL into a 3-byte string.

>call symput ("mftot1","N="|| trim(left(put(total,3.)))!!")"); >run; > >to be used as total like this > > proc sql noprint; > create table V_FINAL_cu1 as >select a.*,a.mi_count/input("&tot1",3.) * 100 as perct , >a.mo_count/input("&tot1",3.) >* 100 as perct1 ,a.se_count/input("&tot1",3.) * 100 as perct2 > from V_FINAL_cu as a ;

You are scanning exactly 3 bytes; all is well.

> quit; > > everything is fine when I am doing this way (above ) but when I trying to >do same thing avoiding call symput (below) the value of &tot is getting >resolved i.e. > >proc sql noprint; >select sum(count) into : tot1

You are relying on explict numeric-to-character conversion. The result is an 8-byte string with the value right-justfied.

>from freq0 >where treat_r ^= ' ' ; >%put &tot1; >quit; > >proc sql noprint; > create table V_FINAL_cu1 as >select a.*,a.mi_count/input("&tot1",3.) * 100 as perct , >a.mo_count/input("&tot1",3.) >* 100 as perct1 ,a.se_count/input("&tot1",3.) * 100 as perct2 > from V_FINAL_cu as a ;

You are scanning only 3 bytes and thus missing at least part of the value and likely all of it.

Just the other day, in a different thread, I anticipated such a situation and cited it as a reason to *not* use the INPUT function in this context. I would replace

input("&tot1",3.)

with just

&tot1

> quit; > > this way &tot1 is not resolving

Yes it is; you're just not scanning it all.

>why ?? and one is there a way I can create >two macro variable using proc sql similar to what I am doing using call >symput ??

Sure. A model:

select max(height), min(weight) into : maxheight, : minweight from sashelp.class;

> >thanks for your time and advice.

You might have had an earlier response if you had made it easier to work on the problem. How? By making it self-contained by including data. It could be as simple as:

data V_AE; TREAT_R = 'abc'; run;

data V_FINAL_cu; retain mi_count 2 mo_count 3 se_count 4; run;


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