Help using Base SAS procedures

Proc Format

Reply
Contributor
Posts: 45

Proc Format

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?

Super User
Posts: 19,789

Re: Proc Format

Posted in reply to SamuelRajKandru

Numbers are characters. 

 

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

Contributor
Posts: 45

Re: Proc Format

JobCode is the variable. 'ME2' and 'SE2' are the values of the variable JobCode.
Super User
Super User
Posts: 7,042

Re: Proc Format

Posted in reply to SamuelRajKandru

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. ;
....
Contributor
Posts: 45

Re: Proc Format

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?
Super User
Super User
Posts: 7,042

Re: Proc Format

Posted in reply to SamuelRajKandru

That should work.

Super User
Posts: 19,789

Re: Proc Format

Posted in reply to SamuelRajKandru

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;

 

 

Contributor
Posts: 45

Re: Proc Format

Reeza, can I copy paste this code and run it? or do I need to edit anything?
Super User
Posts: 19,789

Re: Proc Format

Posted in reply to SamuelRajKandru

Try it...

Contributor
Posts: 45

Re: Proc Format

Below is the screenshot of the output. I think something's wrong?
Super User
Posts: 19,789

Re: Proc Format

Posted in reply to SamuelRajKandru

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.

Contributor
Posts: 45

Re: Proc Format

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
Super User
Posts: 19,789

Re: Proc Format

Posted in reply to SamuelRajKandru

Sorry, typo

 

Want=put(orig, $jobf.);
Contributor
Posts: 45

Re: Proc Format

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


posttypo.png
Super User
Posts: 19,789

Re: Proc Format

Posted in reply to SamuelRajKandru

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

Ask a Question
Discussion stats
  • 18 replies
  • 676 views
  • 6 likes
  • 3 in conversation