BookmarkSubscribeRSS Feed
mj5
Obsidian | Level 7 mj5
Obsidian | Level 7
DATA temp1;
  input subj 1-4 num_val 6 result $8-20 ;
  DATALINES;
1024 1 manual 
1167 1 manual 
1168 2 testing 
1201 2 testing 
1302 3 plain
1302 4 natural
;

data fmtdata;
  set temp1 (rename=(num_val=start result=label));
  by start;
  retain fmtname 'ncodes' type 'N';
  if first.start;
run;

proc format cntlin = fmtdata;
run;

How to call the format?

I am using format num_val $ncodes.;

But it doesnt work

6 REPLIES 6
ChrisBrooks
Ammonite | Level 13

You've created ncodes as a numeric format - it's character formats which have the $ sign at the start so drop that and you should be fine.

mj5
Obsidian | Level 7 mj5
Obsidian | Level 7

Thanks, Can the length be increased for the format name for fmtname as the formats are getting truncated

ChrisBrooks
Ammonite | Level 13

You shouldn't really need to do that - can you post the data and code you're using to apply the format?

Astounding
PROC Star

You can control the number of characters of the formatted value that print.  All of these would be legitimate uses of the same format:

 

format num_val ncodes.;

format num_val ncodes4.;

format num_val ncodes8.;

 

That's the reason that you can't create a format name ending in a digit ... it gives you the flexibility later to add a width when applying the format.

mj5
Obsidian | Level 7 mj5
Obsidian | Level 7

can i sort the formatted character value on basis of numeric.

For example format num_val ncodes.; is there anyway i can sort on basis of numeric values?

Kurt_Bremser
Super User

proc sort will use the raw, unformatted value of a variable. If you want to sort by formatted values, create a new variable that holds those formatted values and sort by that.

Certain SAS procedures can be told to use formatted values in their calculations (ie proc freq).

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1372 views
  • 1 like
  • 4 in conversation