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:
How can I correctly use these tabs and spaces as delimiters and strings, respectively?
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;
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: