Hi all,
If I have a program like this...
*****************************************************
THIS IS A TEST PROGRAM.
PROJECT NUMBER: 123456
*****************************************************;
data a;
var1 = 'hello';
run;
**************** end of program ****************;
... and I want to read it into SAS to edit it with SAS, for example ...
** READ IN **;
data tempa;
infile "U:\test_program_orig.sas" truncover ; ** #1 **;
input line $500. ;
run;
** EDIT **;
data tempb;
set tempa;
if left(upcase(line)) =: 'PROJECT NUMBER' then line = ' Project Number: ' || '09'x || "234567";
run;
** OUTPUT **;
data _null_;
set tempb;
file "U:\test_program_new.sas";
run;
During the READ IN (#1) step, I lose all my indenting (like in the var1= 'hello' statement). Is there an option to retain leading blanks?
Thank you!
Try $char500. as your informat.
Try $char500. as your informat.
Excellent. Thank you!
Follow-up to this...
The CHARxx. format gives you lines with lots of trailing blanks. I discovered that VARYING works well to avoid that.
eol = findc(line, ' ' ,'v', -200); * end of line: v -> find first non-blank, -200 -> R to L *;
if eol = 0 then eol = 1;
put line $varying200. eol;
Someone might find this useful.
@evp000 wrote:
Follow-up to this...
The CHARxx. format gives you lines with lots of trailing blanks. I discovered that VARYING works well to avoid that.
eol = findc(line, ' ' ,'v', -200); * end of line: v -> find first non-blank, -200 -> R to L *;
if eol = 0 then eol = 1;
put line $varying200. eol;
Someone might find this useful.
You might consider the LENGTH function for finding the length of a character variable.
Length takes off the leading blanks and I want to keep them.
Oh, no it doesn't get rid of the leading blanks, so ya, that would work too. Thanks.
You can do it all in one step.
data _null_;
infile cards;
input;
if left(upcase(_infile_)) =: 'PROJECT NUMBER' then _infile_ = ' Project Number: ' || '09'x || "234567";
file log;
put _infile_;
cards4;
*****************************************************
THIS IS A TEST PROGRAM.
PROJECT NUMBER: 123456
*****************************************************;
data a;
var1 = 'hello';
run;
**************** end of program ****************;
;;;;
run;
25 data _null_; 26 infile cards; 27 input; 28 if left(upcase(_infile_)) =: 'PROJECT NUMBER' then _infile_ = ' Project Number: ' || '09'x || "234567"; 29 file log; 30 put _infile_; 31 cards4; ***************************************************** THIS IS A TEST PROGRAM. Project Number: 234567 *****************************************************; data a; var1 = 'hello'; run; **************** end of program ****************;
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.