When I read my input text line, SAS thinks it starts in column 1... but I need to write out another text file with the same indentation that was found in that input text file.
data test;
infile cards;
input line: $1-80;
line_begn_posn = notspace(line);
put line= line_begn_posn=;
cards;
The xyz
%mymacro
myteststring
;
run;
data test; infile cards; input @1 line $char80.; line_begn_posn = notspace(line); put line= line_begn_posn=; cards; The xyz %mymacro myteststring ; run;
Art, CEO, AnalystFinder.com
This works for me:
data test;
infile cards;
input @1 line $char80.;
line_begn_posn = notspace(line);
put line= line_begn_posn=;
cards;
The xyz
%mymacro
myteststring
;
run;
Once you read the value in with the leading blanks ($char80 informat), you can write it out the same way:
data test;
infile cards;
input line $char80.;
put line $char80.;
cards;
The xyz
%mymacro
myteststring
;
Thanks to each of you who has posted a solution!
data test2;
infile cards ;
input @;
line=_infile_;
cards;
The xyz
%mymacro
myteststring
;
run;
The link in my post has an explanation.
@DougZ interesting question indeed.
1.Let me add some spice to the &char80. informat. Place a : (colon) if you were to read as modified list input coz not every record will have values of 80 chars. And in this case we go back to square losing our needed leading blanks
2. ok, if we choose to read with formatted input and NOT modified list input, you are running a risk of reading the next value supposing there are multiple vars to be read
3. Taking 1 and 2 makes this situation indeed tricky. Of course, this leads us to think of next options like $varying informat and use col= options and so on.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.