Date: Thu, 30 Sep 2010 13:51:54 -0500
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: Controlling length of maro variables created using Proc SQL
In-Reply-To: <901048.49005.qm@web57007.mail.re3.yahoo.com>
Content-Type: text/plain; charset=ISO-8859-1
If I recall correctly, if you use the 'separated by' it will trim it for
you, even if it doesn't actually need to [ie, if you have only one value].
IE:
select n(age) format=3. into :g1 separated by ' ' from analysis_data where
strip(treatchar)="&group1"
should do what you ask. Alternately you can do several other things, such
as:
select cats('n=',put(n(age),3.)) into :g1
etc.
-Joe
On Thu, Sep 30, 2010 at 1:36 PM, Paul Miller <pjmiller_57@yahoo.com> wrote:
> Hello Everyone,
>
> I have a question about controlling the length of macro variable created
> using Proc SQL. I want create macro variables that contain the number of
> patients in each of two treatment groups as well as a macro variable
> containing the total number of patients. Then I want to include this
> information in a table I'm making using the ODS Report Writing Interface.
>
> Relevant portions of my code appear below.
>
> proc sql noprint;
> select n(age) format=3. into :g1 from analysis_data where strip(treatchar)
> = "&group1";
> select n(age) format=3. into :g2 from analysis_data where strip(treatchar)
> = "&group2";
> select n(age) format=3. into :t from analysis_data where strip(treatchar)
> in ("&group1" "&group2");
> quit;
>
> obj.row_start(type: "Header");
> obj.format_cell(data: "&varlabel",overrides: "just=l");
> obj.format_cell(data: "&grp1label ^-2n (n=&g1)");
> obj.format_cell(data: "&grp2label ^-2n (n=&g2)");
> obj.format_cell(data: "Total ^-2n (n=&t)");
> obj.row_end();
>
> The problem I'm having stems from the fact that the n's are sometimes 3
> digits and sometimes only 2. When they are 3 digits I get something like
> (n=200) in my table but when thay are only 2 digits I get something like (n=
> 50) instead.
>
> How can I alter my code to remove the extra space so I get (n=50) and still
> have it work for values like (n=200)?
>
> I had thought I could do something like strip(put(n(age),3.)) in my SQL
> code but then I wind up with something like (n=50 ) where the unwanted
> space has moved to the other side.The problem seems to be that the length of
> the macro variable remains 3 even after I apply the strip function. And so I
> need some way of getting it to be the right length.
>
> Thanks,
>
> Paul
>
>
>
>
>
|