Hi I am reading page 278 of the official specialist prep guide.
as you can see from the statement above, there is a space before NY in the above sentence.
so if I use the SCAN function and I specify my delimiters as just a comma with ',' in the third argument in the SCAN function.
data temp;
set cert.staff;
test=scan("209 RADCLIFFE ROAD, CENTER CITY, NY, 92716",3,',');
run;
proc print data=temp;run;
why is it that in the result, the spaces are still removed even though I specified delimiters to be only a comma?
@Nietzsche wrote:why is it that in the result, the spaces are still removed even though I specified delimiters to be only a comma?
The default Style option for displaying almost anything for Proc Print and other ODS tables is ASIS=OFF, which ignores leading spaces. You can change that behavior by overriding the Style setting:
data example; length x $10; x='ABC';output; x=' ABC';output; run; proc print noobs data=example; var x; title 'Default ods behavior'; run; title; proc Print noobs data=example style(data)=[asis=on] ; var x; title "Style ASIS=on"; run;title;
Not all procedures have nice ways to override this behavior and may have to send to output to data sets and use Proc Print, Report or Tabulate to display the data set where you can provide the override.
This is just a feature of html: leading spaces are removed automatically.
EDIT: Replacing blanks with underscores shows the real value in html, too:
data temp;
test = scan("209 RADCLIFFE ROAD, CENTER CITY, NY, 92716", 3, ',');
test = translate(test, '_', ' ');
run;
The leading space is not removed, and was not counted as a delimiter.
The space is in the value:
1 data temp;
2 test=scan("209 RADCLIFFE ROAD, CENTER CITY, NY, 92716",3,',');
3 if test="NY" then put "space was removed" ;
4 else if test=" NY" then put "space was not removed" ;
5 run;
space was not removed
NOTE: The data set WORK.TEMP has 1 observations and 1 variables.
The last image looks to be the output generated using ODS.
ODS does NOT preserve leading spaces.
Look at the PROC PRINT that is generated to the LISTING (plain old text file) output to see the leading space(s).
Or attach the $QUOTE format to the variable so that ODS will not eat the leading space since there will then be a quote character in front of it.
@Nietzsche wrote:why is it that in the result, the spaces are still removed even though I specified delimiters to be only a comma?
The default Style option for displaying almost anything for Proc Print and other ODS tables is ASIS=OFF, which ignores leading spaces. You can change that behavior by overriding the Style setting:
data example; length x $10; x='ABC';output; x=' ABC';output; run; proc print noobs data=example; var x; title 'Default ods behavior'; run; title; proc Print noobs data=example style(data)=[asis=on] ; var x; title "Style ASIS=on"; run;title;
Not all procedures have nice ways to override this behavior and may have to send to output to data sets and use Proc Print, Report or Tabulate to display the data set where you can provide the override.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.