- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Just use the TRIMMED option in PROC SQL.
https://documentation.sas.com/doc/en/pgmsascdc/v_009/sqlproc/n1tupenuhmu1j0n19d3curl9igt4.htm
select PName
into :plate trimmed
from test
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Just use the TRIMMED option in PROC SQL.
https://documentation.sas.com/doc/en/pgmsascdc/v_009/sqlproc/n1tupenuhmu1j0n19d3curl9igt4.htm
select PName
into :plate trimmed
from test
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Trimmed worked !!!