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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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

 

 

View solution in original post

4 REPLIES 4
Lucy1
Fluorite | Level 6

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

 

GBL__
Quartz | Level 8
This is great! Thank you for your reply, @Lucy1
novinosrin
Tourmaline | Level 20

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

 

 

GBL__
Quartz | Level 8
Thank you @novinosrin ! I did not remember about the alignment overrides. Much Appreciated!

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1347 views
  • 0 likes
  • 3 in conversation