SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Stalk
Pyrite | Level 9

I need to capture a value from the text field and use that as dataset or filename. But I am having issues with removing the leading and tailing blank spaces.

My goal is to create a report and save the file as "RFPVER05567 Row_2BRHTUHB.pdf"

No matter what I do now, my file is saved as "RFPVER05567 Row_2BRHTUHB                   .pdf" or

"            RFPVER05567 Row_2BRHTUHB.pdf".

Any suggestions?

proc sql noprint;
select distinct right(PName) into :plate from test ;
select distinct strip(pName) into :plate_st from test;
select distinct compress(pName) into :plate_cp from test;
quit;

pName=RFPVER05567 Row_2BRHTUHB

 

Thank you

1 ACCEPTED SOLUTION
3 REPLIES 3
ballardw
Super User

@Stalk wrote:

I need to capture a value from the text field and use that as dataset or filename. But I am having issues with removing the leading and tailing blank spaces.

My goal is to create a report and save the file as "RFPVER05567 Row_2BRHTUHB.pdf"

No matter what I do now, my file is saved as "RFPVER05567 Row_2BRHTUHB                   .pdf" or

"            RFPVER05567 Row_2BRHTUHB.pdf".

Any suggestions?

proc sql noprint;
select distinct right(PName) into :plate from test ;
select distinct strip(pName) into :plate_st from test;
select distinct compress(pName) into :plate_cp from test;
quit;

pName=RFPVER05567 Row_2BRHTUHB

 

Thank you


Right would be "right out" for your purpose as it would right align the value in the variable. In any situation where the text was less than the variable defined length you would have inserted leading blanks.

Compress doesn't consider "trailing blanks" as something to remove just due to the way SAS character variables are handled generally in relation to defined length.

 

If you are actually selecting multiple values into a single macro variable you should consider indicating the separation character, otherwise only the first value returned by the select is placed into the macro variable.

data example;
   input word $;
datalines;
abc
pdq
;

proc sql;
select distinct strip(word) into :plate_st from example;
select distinct strip(word) into :plate_st2 separated by ' ' from example;
quit;

%put Plate_st is:&plate_st;
%put Plate_st2 is:&plate_st2.;
 

Which will show the values of the macro variables in the log:

27   %put Plate_st is:&plate_st;
Plate_st is:abc
28   %put Plate_st2 is:&plate_st2.;
Plate_st2 is:abc pdq

Note only a single value in the first one. Which might have been a clue that your syntax was incomplete.

Stalk
Pyrite | Level 9
I'm trying to create a single macro variable. Thank you.
Trimmed worked !!!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1216 views
  • 1 like
  • 3 in conversation