- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Get file with record over 4 lines(sample below)... How to read-in over lines (var names do not matter, just var1/2/3/...).
GAS 6246.00 2203 5111
1135 18.17%
2204 6134
112 1.79%
PORK 12.40 2203 11215
1185 9.56%
2205 14210
-1810 -14.60%
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
IF every record takes the same number of lines in the source then write a data step to read the data and your INFILE statement uses the N= option to specify that number. Then use the # in the INPUT statement to indicate which line to read specific variables from.
data example; infile datalines n=4; input var1 $ varw var3 var5 #2 var6 var7 :commax. #3 var8 var9 #4 var10 var11 :commax. ; format var7 var11 percent8.2; datalines; GAS 6246.00 2203 5111 1135 18.17% 2204 6134 112 1.79% PORK 12.40 2203 11215 1185 9.56% 2205 14210 -1810 -14.60% ;
If your data has varying number of lines per record this likely won't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please see the section entitled "Line Pointer Controls" here. Essentially using a / or the # operator lets your INPUT statement read from multiple lines.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
IF every record takes the same number of lines in the source then write a data step to read the data and your INFILE statement uses the N= option to specify that number. Then use the # in the INPUT statement to indicate which line to read specific variables from.
data example; infile datalines n=4; input var1 $ varw var3 var5 #2 var6 var7 :commax. #3 var8 var9 #4 var10 var11 :commax. ; format var7 var11 percent8.2; datalines; GAS 6246.00 2203 5111 1135 18.17% 2204 6134 112 1.79% PORK 12.40 2203 11215 1185 9.56% 2205 14210 -1810 -14.60% ;
If your data has varying number of lines per record this likely won't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What if the info is in a file?! I tried below, it goes wack thou
data example;
infile "C:\Users\24891\Desktop\sasOUT\20220301_copy.csv" n=4;
input var1 $ varw var3 var5
#2 var6 var7 :comma4.
#3 var8 var9
#4 var10 var11 :comma4.
;run;quit;
- Tags:
- T
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Whether a file or as in-line data it should work the same.
How does it not work?
Does the actual file not follow the pattern of your example lines?
Why does the file have a CSV extension? The sample lines you showed look nothing like a CSV file there weren't any commas on any of the lines.
To look the beginning of the file run a simple data step to dump the first lines to the SAS log.
data _null_;
infile "C:\Users\24891\Desktop\sasOUT\20220301_copy.csv" obs=5;
input;
list;
run;