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

I have created a SAS dataset that has the formats that I want to load.

Some formats have range and some of them have just labels.

The range and just label formats don't load together. How can I create one dataset that has all the formats (range,label,numeric,character,date) and I load them at once.

Please send me a link to any examples.

 

Example

fmtname,start,end,label,hlo

score,-999,400,Score 1,L

score,401,800,Score 2,

score,801,9999,Score 3,H

 

product,1,,Product 1,

product,2,,Product 2,

 

proc sort data=myformats
   by fmtname start;
run;

PROC FORMAT CNTLIN=myformats;
RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

I dont think it is possible to create the numeric format and character format from the same dataset using proc format CNTLIN option.

 

You have to create separate datasets for numeric format and character format then use separate proc format CNTLIN option. 

 

data have;
type='N'; 
fmtname='range';
hlo='L';
start=.;
end=10000;
label='<= 100,000';
output;
type='N'; 
fmtname='range';
hlo=' ';
start=100001;
end=250000;
label='> 100,000';
output;
type='N'; 
fmtname='range';
hlo=' ';
start=250001;
end=400000;
label='> 250,000';
output;
type='N'; 
fmtname='range';
hlo=' ';
start=400001;
end=500000;
label='> 400,000';
output;
type='N'; 
fmtname='range';
start=500001;
end=.;
hlo='H';
label='> 500,000';
output;
run;

data have2;
/*character format*/
type='C'; 
fmtname='$sexsg';
start='F';
label='Female';
output;
type='C'; 
fmtname='$sexsg';
start='M';
label='Male';
output;
run;


proc format cntlin=have fmtlib;
run;

proc format cntlin=have2 fmtlib;
run;

Thanks,
Jag

View solution in original post

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16

I dont think it is possible to create the numeric format and character format from the same dataset using proc format CNTLIN option.

 

You have to create separate datasets for numeric format and character format then use separate proc format CNTLIN option. 

 

data have;
type='N'; 
fmtname='range';
hlo='L';
start=.;
end=10000;
label='<= 100,000';
output;
type='N'; 
fmtname='range';
hlo=' ';
start=100001;
end=250000;
label='> 100,000';
output;
type='N'; 
fmtname='range';
hlo=' ';
start=250001;
end=400000;
label='> 250,000';
output;
type='N'; 
fmtname='range';
hlo=' ';
start=400001;
end=500000;
label='> 400,000';
output;
type='N'; 
fmtname='range';
start=500001;
end=.;
hlo='H';
label='> 500,000';
output;
run;

data have2;
/*character format*/
type='C'; 
fmtname='$sexsg';
start='F';
label='Female';
output;
type='C'; 
fmtname='$sexsg';
start='M';
label='Male';
output;
run;


proc format cntlin=have fmtlib;
run;

proc format cntlin=have2 fmtlib;
run;

Thanks,
Jag
andreas_lds
Jade | Level 19

The value "product" is not a valid name for a char-format, if you don't use the type variable.

Can you please post the datasets "myformats" using datalines, so that we have the same starting point.

Sanjay_M
Obsidian | Level 7

Hi Andrea, my apologies. I was only trying to describe as an example and is not the actual data. The example that jag has provided above is exactly what I need in addition to another format that would be numeric with labels and not range.

Also, how does 'type' column help proc statement PROC FORMAT CNTLIN

Reeza
Super User
Type explicitly tells SAS if you're creating a numeric or character format.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 1873 views
  • 1 like
  • 4 in conversation