BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Nietzsche
Lapis Lazuli | Level 10

Hi I am reading page 278 of the official specialist prep guide. 

 

 

Nietzsche_0-1668488868183.png

 

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_1-1668489742363.png

 

 

 

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@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.

View solution in original post

4 REPLIES 4
andreas_lds
Jade | Level 19

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;
Quentin
Super User

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.
Tom
Super User Tom
Super User

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.

ballardw
Super User

@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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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