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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1078 views
  • 0 likes
  • 3 in conversation