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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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