I'm a new SAS programmer and am trying to figure out how to read in column headers for a data frame from a text file. The problem is the data look like this:
Var1 Var2 Var3
Var4 Var5 Var6
1 data for 1
data for 1
2 data for 2
data for 2
...
And My output looks like this:
obs Var1 Var2 Var3
1 Var4 Var5 Var6
2 1 data for 1
...
This is what I have so far any feedback I appreciate.
PROC IMPORT DATAFILE= "/folders/myfolders/file.txt" out = WORK.MYOUTPUT DBMS= TAB replace;
getnames = yes;
Is your file organized so that every observation takes two lines? Or is just the "header" split into two lines?
Is the split at the same place for every observation (and for the headers?).
You probably will want to skip asking SAS to guess how to read the file and just tell it explicitly how to read it.
data want;
infile "/folders/myfolders/file.txt" dsd truncover firstobs=3;
input var1 var2 var3 / var4 var5 var6;
run;
For more detailed answer show some actual example (or a representative example) of the lines in the file. Don't paste the lines into the test of your message. Instead use the Insert Code button so you get a pop-up window where you can past text so it will be displayed using fixed width font and it will not be flowed into paragraphs.
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 25. 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.