BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LB
Quartz | Level 8 LB
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

8 REPLIES 8
data_null__
Jade | Level 19

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

%let num1=&num1;

%let num2=&num2;

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

LB
Quartz | Level 8 LB
Quartz | Level 8

Thanks data_null_!

That helped!

Lawrence


MikeZdeb
Rhodochrosite | Level 12

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/Tips:Strip_Blanks_from_PROC_SQL-Created_Macro_Variable_Values

PGStats
Opal | Level 21

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
data_null__
Jade | Level 19

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

Linlin
Lapis Lazuli | Level 10

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|

Astounding
PROC Star

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.

LB
Quartz | Level 8 LB
Quartz | Level 8

Astounding-

Thanks for the tip. That helps.

Lawrence

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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