BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
evp000
Quartz | Level 8

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!

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
7 REPLIES 7
SASKiwi
PROC Star

Try $char500. as your informat.

evp000
Quartz | Level 8

Excellent.  Thank you!

evp000
Quartz | Level 8

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.

data_null__
Jade | Level 19

@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.

evp000
Quartz | Level 8

Length takes off the leading blanks and I want to keep them. 

evp000
Quartz | Level 8

Oh, no it doesn't get rid of the leading blanks, so ya, that would work too.  Thanks. 

data_null__
Jade | Level 19

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 ****************;  

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2884 views
  • 1 like
  • 3 in conversation