BookmarkSubscribeRSS Feed
Junyong
Pyrite | Level 9

The following data have both tabs (delimiters) and spaces (not delimiters). I tried EXPANDTABS with a colon in INPUT as follows:

data international_stock_exchanges;
	infile cards expandtabs truncover;
	input EXCHGCD EXCHGDESC :$80. Country $80.;
cards;
0	Subsidiary/Private	Canada
0	Subsidiary/Private	United States
1	Non-traded Company or Security	Canada
1	Non-traded Company or Security	Germany
1	Non-traded Company or Security	Switzerland
1	Non-traded Company or Security	Taiwan
1	Non-traded Company or Security	United States
2	Consolidated Parent or Tracking Stock Company	United States
3	Leveraged Buyout	United States
4	Additional Company Record-PreSFAS 94, ProForma, PreAmended	United States
;

However, this colon made the second variable EXCHGDESC skip also at spaces as well as tabs as follows:

220714.png

How can I correctly use these tabs and spaces as delimiters and strings, respectively?

2 REPLIES 2
SASKiwi
PROC Star
data international_stock_exchanges;
	infile cards truncover dlm = '09'x;
	input EXCHGCD EXCHGDESC :$80. Country $80.;
cards;
0	Subsidiary/Private	Canada
0	Subsidiary/Private	United States
1	Non-traded Company or Security	Canada
1	Non-traded Company or Security	Germany
1	Non-traded Company or Security	Switzerland
1	Non-traded Company or Security	Taiwan
1	Non-traded Company or Security	United States
2	Consolidated Parent or Tracking Stock Company	United States
3	Leveraged Buyout	United States
4	Additional Company Record-PreSFAS 94, ProForma, PreAmended	United States
;
run;
Tom
Super User Tom
Super User

To read delimited data use the DSD option on the INFILE statement.  Use the DLM= option to change the delimiter. You can represent a tab character as hexadecimal literal string '09'x.  Do not replace the tabs with spaces.

data international_stock_exchanges;
  infile 'myfile.txt' dsd dlm='09'x truncover;
  input EXCHGCD EXCHGDESC :$80. Country $80.;
run;

But DO NOT include physical TAB characters in CODE.  That includes in-line datalines.  The SAS Program editor in SAS's Display Manager interactive environment will replace the tabs with spaces (like the EXPANDTABS option in your posted data step does) when it sends to the code to be run.  Now some environments, like SAS/Studio interface, will actually pass those tab characters into the data stream, but if you give your program to someone else to use and they have choosen to use the option to replace tabs with actual spaces then as soon as they edit your file the tabs will be gone.

 

If you do want to include the data in-line then just replace the tabs with some other character.

0|Subsidiary/Private|Canada
0|Subsidiary/Private|United States
1|Non-traded Company or Security|Canada
1|Non-traded Company or Security|Germany
1|Non-traded Company or Security|Switzerland
1|Non-traded Company or Security|Taiwan
1|Non-traded Company or Security|United States
2|Consolidated Parent or Tracking Stock Company|United States
3|Leveraged Buyout|United States
4|Additional Company Record-PreSFAS 94, ProForma, PreAmended|United States

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 2 replies
  • 1483 views
  • 0 likes
  • 3 in conversation