Good Morning!
I am using formats extensively within my project to assign values/descriptions to codes within variables. My question specifically is if I need to add spaces on the left side of the format definitions so SAS identifies the correct code, or if that is not necessary?
i.e. Will SAS format this correctly:
"A" = "Something"
"ABC" = "Something Else"
"ABCD01" = "The Other Thing"
Or do I need to add spaces:
"A " = "Something"
"ABC " = "Something Else"
"ABCD01" = "The Other Thing"
ETA: I am using these formats to create new variables after importing the raw data files with a PUT statement:
PUT(raw_data_codes, $my_format.) AS NEW_VARIABLE ,
Thank you in advance for your help! Much Appreciated!
Hi @GBL__ I'd think both forms are equivalent as trailing blanks do not matter, rather the problem is leading blank. So when assigning a format label using put function, it's always a good idea to use put(key,label. -l) Left align so that we present no scope of an occurrence of a leading blank
The characters that are looked for in the data are exact matches, they do not need to be the same length. Have you tried running this will code?
Here is an example you could run for proof:
proc format;
value $myfmt "A" = "Something"
"ABC" = "Something Else"
"ABCD01"= "The Other Thing";
run;
data have;
length var $10;
var='A';output;
var='ABCD01';output;
var='AB';output;
run;
data want;
set have;
new_var=put(var, $myfmt.);
run;
and the output
Hi @GBL__ I'd think both forms are equivalent as trailing blanks do not matter, rather the problem is leading blank. So when assigning a format label using put function, it's always a good idea to use put(key,label. -l) Left align so that we present no scope of an occurrence of a leading blank
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.