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 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 20 Apr 2007 15:25:53 -0400
Reply-To:   Jack Clark <JClark@CHPDM.UMBC.EDU>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Jack Clark <JClark@CHPDM.UMBC.EDU>
Subject:   Re: Unexpected output
Comments:   To: Irin later <irinfigvam@yahoo.com>
In-Reply-To:   <498468.35147.qm@web34109.mail.mud.yahoo.com>
Content-Type:   text/plain; charset="us-ascii"

Irin,

Sorry, I thought the num1, num2 etc. references were to data set variables. This approach loads the number of observations from each data set into macro variables, then calculates the percent and loads it into a macro variable. Then the PUT statement is used to generate the output. I wasn't clear on exactly what you need your output to look like, but hopefully this can get you started.

** build sample data ;

%macro buildds (ds=,numobs=);

data &ds;

do i = 1 to &numobs;

x = 'X';

output;

end;

run;

%mend buildds;

%buildds (ds=num1,numobs=100);

%buildds (ds=denom1,numobs=1000);

%buildds (ds=num2,numobs=150);

%buildds (ds=denom2,numobs=1000);

** load macro variables ;

data _null_;

%macro calc (dscnt=);

%do i = 1 %to &dscnt;

dsidn=open("num&i");

num&i=attrn(dsidn,"nlobs");

call symputx("num&i.obs",put(num&i,12.));

dsidd=open("denom&i");

denom&i=attrn(dsidd,"nlobs");

call symputx("denom&i.obs",put(denom&i,12.));

call symputx("pct&i.",put(num&i/denom&i,7.2));

%end;

%mend calc;

%calc (dscnt=2);

run;

** generate output ;

data _null_;

file print;

%macro prnt (pcnt=);

%do i = 1 %to &pcnt;

put "Percent = num&i / denom&i &&pct&i = &&num&i.obs/&&num&i.obs";

%end;

%mend prnt;

%prnt (pcnt=2);

run;

P.S. to other SAS-L members

I don't usually use the OPEN statement, and I remember seeing posts on SAS-L (I think from the macro maven) about closing data sets after opening them with the OPEN statement. Reading the doc, it says the data set is automatically closed at the end of the DATA step. Any comments or code suggestions related to this would be of interest.

Jack Clark

Research Analyst

Center for Health Program Development and Management

University of Maryland, Baltimore County

________________________________

From: Irin later [mailto:irinfigvam@yahoo.com] Sent: Friday, April 20, 2007 2:14 PM To: Jack Clark; SAS-L@LISTSERV.UGA.EDU Subject: Re: Unexpected output

Jack, thing is that num1, denom1, num2; denom2 are all input datasets

In other words log tells me that num1 has 10 records, denom1 caontains 20 records and I need to calculate the percentage.

Is there anyway to do it? Sorry everyone for the confusion that I realeased after had read Jack's question about datasets.

num1, denom1, num2; denom2 are all input datasets which have different number of observations. That what I need to have in my output

Is there any way to implement it?

Thank you in advance

Jack Clark <JClark@CHPDM.UMBC.EDU> wrote:

Irin, Move your references to the variables outside of the quotes. Another thing, I don't see any input dataset in your example. Jack Clark Research Analyst Center for Health Program Development and Management University of Maryland, Baltimore County -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Irin later Sent: Friday, April 20, 2007 1:31 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Unexpected output I am trying to get an output using the following code: data _null_; file print; put "Percent=num1/denom1 Percent=num1/denom1"; ... run; And I got unexpected output: Percent=num1/denom1 Percent=num1/denom1 Percent=num2/denom2 Percent=num2/denom2 .... In other words I did not get any numbers.....while my num1; denom1; num2; den2 are definitely numbers. What do you think I am doing wrong? Thank you in advance, Irin --------------------------------- Ahhh...imagining that irresistible "new car" smell? Check outnew cars at Yahoo! Autos.

________________________________

Ahhh...imagining that irresistible "new car" smell? Check out new cars at Yahoo! Autos. <http://us.rd.yahoo.com/evt=48245/*http:/autos.yahoo.com/new_cars.html;_ ylc=X3oDMTE1YW1jcXJ2BF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDbmV3LWNhcnM- >


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