- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Numbers are characters.
Are ME2/SE2 variables or values your having issues with? Please explain in detail.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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. ;
....
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That should work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Try it...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, typo
Want=put(orig, $jobf.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Okay, corrected the code and submitted it. There weren't any errors or warnings in the log.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So, are the results what you want? If so, your done.