Help using Base SAS procedures

declaring macro parameters in PROC SQL and length issues

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 133
Accepted Solution

declaring macro parameters in PROC SQL and length issues

Hi all-

I have an issue that has been confounding me to no end-

I have a query that goes like this-

PROC SQL;

SELECT sum(CASE WHEN COMPLIANT='NO' then 1 else 0 END),count(*)

into :NUM1, :NUM2

from XYZ

where put(FAC_ID,$shortfix.)='XXX'

/*group by FAC_ID*/

quit;

When I call the macro variables NUM1 and NUM2, NUM1 has a big trailing space-

I have attempted to modify it as putting it as a character variable to no avail.

NUM2 works just fine.

Any answers, solutions would be great.

Thanks

Lawrence


Accepted Solutions
Solution
‎06-04-2012 12:46 PM
Respected Advisor
Posts: 3,777

Re: declaring macro parameters in PROC SQL and length issues

This should remove the spaces, I think....

%let num1=&num1;

%let num2=&num2;

%put NOTE: did it work **&num1** **&num2**;

View solution in original post


All Replies
Solution
‎06-04-2012 12:46 PM
Respected Advisor
Posts: 3,777

Re: declaring macro parameters in PROC SQL and length issues

This should remove the spaces, I think....

%let num1=&num1;

%let num2=&num2;

%put NOTE: did it work **&num1** **&num2**;

Frequent Contributor
Frequent Contributor
Posts: 133

Re: declaring macro parameters in PROC SQL and length issues

Thanks data_null_!

That helped!

Lawrence


Valued Guide
Posts: 765

Re: declaring macro parameters in PROC SQL and length issues

hi ... you could also try ...

data x;

retain a b 5;

run;


proc sql noprint;

select a, b into :num1 separated by ' ', :num2 separated by ' '  from x ;

quit;


%put |&num1|&num2|;

|5|5|

from ...

http://www.sascommunity.org/wiki/TipsSmiley Frustratedtrip_Blanks_from_PROC_SQL-Created_Macro_Variable_Values

Respected Advisor
Posts: 4,659

Re: declaring macro parameters in PROC SQL and length issues

Or...

data x;
retain a b 555555555555;
format b best15.;
run;

proc sql noprint;
select a, b into :num1 trimmed, :num2 trimmed  from x ;
quit;

%put |&num1|&num2|;

|5.556E11|555555555555|

PG

PG
Respected Advisor
Posts: 3,777

Re: declaring macro parameters in PROC SQL and length issues

What version of SAS are you using?  That doesn't work with my SAS 9.2.

Super Contributor
Posts: 1,636

Re: declaring macro parameters in PROC SQL and length issues

Hi Data _null_,

It works with my SAS 9.3.

5

6    proc sql noprint;

7    select a, b into :num1 trimmed, :num2 trimmed  from x ;

8    quit;

NOTE: PROCEDURE SQL used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

9

10   %put |&num1|&num2|;

|5.556E11|555555555555|

Super User
Posts: 5,093

Re: declaring macro parameters in PROC SQL and length issues

You've already gotten solutions.  This is just for insight ...

Macro variables hold character strings only.  When SQL extracts a numeric value, and the into : operator requests that it be stored in a macro variable, SQL has to perform a numeric to character conversion.  Off the top of my head it uses an 8-character width, rather than the 12-character width that CALL SYMPUT would use.  However, unlike a DATA step, SQL doesn't give you a note that conversion is taking place.  At any rate, the blanks you are witnessing are leading blanks (for both variables), rather than trailing blanks, produced by the conversion process.

Good luck.

Frequent Contributor
Frequent Contributor
Posts: 133

Re: declaring macro parameters in PROC SQL and length issues

Astounding-

Thanks for the tip. That helps.

Lawrence

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 424 views
  • 6 likes
  • 6 in conversation