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

I have the outputs of PROC CONTENTS, and I am trying to create a macro variable of something in the NAME column of the PROC CONTENTS output. I try this via a DATA step, and also via PROC SQL.

The following code, working on the same data set, should produce two macro variables with the exact same values (in my opinion), but it does not. There are extra blanks appended to the second macro variable. Why? How can I fix this so PROC SQL produces a macro variable without the extra blanks?

data _null_;

  set _cont_(where=(upcase(name)='PARAM_NUM' or upcase(name)='PARM_NUM'));

  call symputx('parm_num1',name);

run;

proc sql noprint;

  select distinct trim(name) into :parm_num2 from _cont_ where upcase(name) eqt 'PARAM_NUM' or upcase(name) eqt 'PARM_NUM';

quit;

%put PARM_NUM1 &parm_num1 ****;

%put PARM_NUM2 &parm_num2 ****;

The results I get from the PUT statements show the values are different with PARM_NUM2 appearing to have extra blanks:

1110      %put PARM_NUM1 &parm_num1 ****;

PARM_NUM1 parm_num ****

1111      %put PARM_NUM2 &parm_num2 ****;

PARM_NUM2 parm_num                         ****

--
Paige Miller
1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

Use TRIMMED option

17         proc sql;
18            select name into :name1 from sashelp.class(obs=1);
19            %put NOTE: name1=*&name1*;
NOTE: name1=*Alfred  *
20            select name into :name2 trimmed from sashelp.class(obs=1);
21            %put NOTE: name2=*&name2*;
NOTE: name2=*Alfred*
22            quit;

View solution in original post

4 REPLIES 4
data_null__
Jade | Level 19

Use TRIMMED option

17         proc sql;
18            select name into :name1 from sashelp.class(obs=1);
19            %put NOTE: name1=*&name1*;
NOTE: name1=*Alfred  *
20            select name into :name2 trimmed from sashelp.class(obs=1);
21            %put NOTE: name2=*&name2*;
NOTE: name2=*Alfred*
22            quit;
Ksharp
Super User

or using

select distinct trim(name) into :parm_num2 separated by ' '  from _cont_

Ksharp

UrvishShah
Fluorite | Level 6

Hi,

By Default, CALL SYMPUT will maintain any leading or trailling blanks...In below example program, i have created name which have 20 bytes length but originally there is only 3 bytes so name will have 17 extra trailling blanks which is going to retain while creating macro variable by using CALL SYMPUT during data step execution...

But if you use CALL SYMPUTX insted of CALL SYMPUT then it will remove any leading or trailling blanks from the variable...Here, CALL SYMPUT "X" represents EXTRA BLANKS to be remove and in contrast, PROC SQL will retain any leading or trailing blanks while creating macro variable during proc sql execution...

SEE THE BELOW EXAMPLE PROGRAME...HOPE IT HELPS...

  data test;

   length name $20.;

  name = "XYZ";

    call symputx("data_X_name",name);

    call symput("data_name",name);

run;

proc sql noprint;

    select name into :sql_name

    from test;

quit;

%put CALL SYMPUT will resolve to: &data_name.*****;

%put CALL SYMPUTX will resolve to: &data_x_name.*****;

%put PROC SQL will resolve to: &sql_name.*****;

-Urvish

PaigeMiller
Diamond | Level 26

Great stuff, guys, thank you very much.

--
Paige Miller

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 924 views
  • 4 likes
  • 4 in conversation