BookmarkSubscribeRSS Feed
SamuelRajKandru
Quartz | Level 8

How do you create a (proc) format for a variable having mixed values (character and numeric) like ME2 and SE2 ? Is it possible? Or is there any other way?

18 REPLIES 18
Reeza
Super User

Numbers are characters. 

 

Are ME2/SE2 variables or values your having issues with? Please explain in detail. 

SamuelRajKandru
Quartz | Level 8
JobCode is the variable. 'ME2' and 'SE2' are the values of the variable JobCode.
Tom
Super User Tom
Super User

If you variable JOBCODE has values like 'ME2' then you have a character variable. You will need to use a character format.

 

proc format;
  value $jobcode
   'ME2'='Must Enter Twice'
  ;
run;
....
format jobcode $jobcode. ;
....
SamuelRajKandru
Quartz | Level 8
proc format;
value $Jobf
'TA2'='MANAGER'
'ME2'='ASSISTANT'
'ME1'='TECHNICAL WRITER'
'FA3'='SENIOR TECHNICAL WRITER'
'TA3'='ASST MANAGER'
'ME3'='ASSISTANT ASST'
'SCP'='TIME PASS';
RUN;


Is this code correct?
Tom
Super User Tom
Super User

That should work.

Reeza
Super User

Close, but probably not the way you want. YOU should always test your code.

To test a format, test all values AND some values that aren't in your list. 

 

proc format;
value $Jobf
'TA2'='MANAGER'
'ME2'='ASSISTANT'
'ME1'='TECHNICAL WRITER'
'FA3'='SENIOR TECHNICAL WRITER'
'TA3'='ASST MANAGER'
'ME3'='ASSISTANT ASST'
'SCP'='TIME PASS';
RUN;

data test;
input orig $5.;
want=put("TA2", $jobf.);
cards;
TA2
ME2
ME1
FA3
TA3
ME3
SCP
XXX
YYY
AAA
TB24
TA24
ME23
;
run;

proc print data=test;run;

 

 

SamuelRajKandru
Quartz | Level 8
Reeza, can I copy paste this code and run it? or do I need to edit anything?
Reeza
Super User

Try it...

SamuelRajKandru
Quartz | Level 8
Below is the screenshot of the output. I think something's wrong?
Reeza
Super User

@SamuelRajKandru wrote:
Below is the screenshot of the output. I think something's wrong?

Yes, that was the point of this little exercise, though not as bad as your output.

Check the log to make sure no errors occurred.

SamuelRajKandru
Quartz | Level 8
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
55
56 data test;
57 input orig $5.;
58 want=put("TA2", $jobf.);
59 cards;
 
NOTE: The data set WORK.TEST has 13 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.00 seconds
 
73 ;
 
74 run;
75
76 proc print data=test;run;
 
NOTE: There were 13 observations read from the data set WORK.TEST.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.07 seconds
cpu time 0.08 seconds
 
 
77
78 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
90
Reeza
Super User

Sorry, typo

 

Want=put(orig, $jobf.);
SamuelRajKandru
Quartz | Level 8

Okay, corrected the code and submitted it. There weren't any errors or warnings in the log.


posttypo.png
Reeza
Super User

So, are the results what you want? If so, your done. 

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!

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
  • 18 replies
  • 3629 views
  • 6 likes
  • 3 in conversation