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
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;
have you tried prepending '09'x as the tab character?
Greetings, I'm sorry but i'm new to programming and i'm not sure how can i do that.
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;
That worked like a charm. Thank you!
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!
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.