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

Greetings,

 

I Have a script to generate a SAS program file (txt) using a data step like this:

data outem.bound;
	set outem.model;
	attrib txt length = $2000.;
		txt = "***********************Macros for imputation of variable "!!trim(dep)!!"****************;";
		output;
		txt = "%"!!"macro bound"!!trim(dep)!!";";
		output;
		if not missing(lb) then do;
			txt =     '     '!!"      LB="!!trim(lb)!!";";
			output;
		end;
		if not missing(ub) then do;
			txt =     '     '!!"      UB="!!trim(ub)!!";";
			output;
		end;
		if not missing(dlb) and not missing(lb) then do;
			txt =     '      '!!"          LB=MAX(LB,"!!trim(dlb)!!");";
			output;
		end;
		if not missing(dlb) and missing(lb) then do;
			txt =      '     '!!"      LB="!!trim(dlb)!!";";
			output;
		end;
		if not missing(dub) and not missing(ub) then do;
			txt =        '     '!!"    UB=MIN(UB,"!!trim(dub)!!");";
			output;
		end;
		if not missing(dub) and missing(ub) then do;
			txt = '     '!!"UB="!!trim(dub)!!";";
			output;
		end;
		txt = "%"!!"mend;";
		output;
run;
data outem.imp;
    set outem.bound;
    file "&mydir\3_generate_models\3_model.sas" lrecl = 2000;
    put txt;
run;

The program works just fine. However I cannot put empty space before or after any string.

For instance, the scrip generates this string:

%macro boundHC0340;
LB=           1;
UB=           9;
%mend;

But i would like to have this instead:

%macro boundHC0340;
    LB=           1;
    UB=           9;
%mend;

I can put other characters such as "*" or "#". It's just that I can't put empty space before LB or UB

Thank you very much for your support.

 

Best regards

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

To get PUT to not remove the leading spaces you need use a format.  You could use $CHAR format, but it would be better to use $VARYING and avoid padding your program file lines with trailing spaces.

data outem.imp;
    set outem.bound;
    file "&mydir\3_generate_models\3_model.sas" lrecl = 2000;
    length=lengthn(txt);
    put txt $varying2000. length;
run;

View solution in original post

4 REPLIES 4
DBailey
Lapis Lazuli | Level 10

have you tried prepending '09'x as the tab character?

Luis_Martins
Fluorite | Level 6

Greetings, I'm sorry but i'm new to programming and i'm not sure how can i do that. 

Tom
Super User Tom
Super User

To get PUT to not remove the leading spaces you need use a format.  You could use $CHAR format, but it would be better to use $VARYING and avoid padding your program file lines with trailing spaces.

data outem.imp;
    set outem.bound;
    file "&mydir\3_generate_models\3_model.sas" lrecl = 2000;
    length=lengthn(txt);
    put txt $varying2000. length;
run;
Luis_Martins
Fluorite | Level 6

That worked like a charm. Thank you!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 4 replies
  • 1919 views
  • 0 likes
  • 3 in conversation