Help using Base SAS procedures

Questions about multiple labels in PROC FORMAT

Reply
Occasional Contributor THS
Occasional Contributor
Posts: 5

Questions about multiple labels in PROC FORMAT

Hi ~  I'm learning the PROC FORMAT CNTLIN part, but have some troubles if the data having multiple labels ...

For example :

 

IF Code 101,102,103 are classified as A disease ;  code 101 ,105 are  classified as B disease

If the data sets are as followed 

ID              CODE

1                101

2                102

3                103

4                105

and wish after using proc format with CNTLIN function ;

the data set would be turned into

ID                  CODE            Classifications

1                      101                A

1                      101                B

2                      102                A

3                      103                A

4                      105                B

---

DATA test ;

INPUT ID 1 CODE $5-7;

datalines;

1 101    

2 102

3 103

4 105

;

run;

DATA NAME;

INPUT CODE $1-3 DZ $5;

datalines;

101 A

102 A

103 A

101 B

105 B

;

run;

DATA fmttest;

set name;

rename code=start dz=label;

retain fmtname "$dz" ;

HLO="M";

run;

PROC FORMAT CNTLIN=fmttest;run;

data test2;

set test;

dz=put(code,$dz.);

run;

but it seems not work at all .. is it possible to use PROC FORMAT with CNTLIN  with multiple label function in this way ?

Thanks a lot

Super User
Super User
Posts: 7,079

Re: Questions about multiple labels in PROC FORMAT

I think you need to add the TYPE variable to your CNTLIN dataset since you are defining an character format instead of a numeric format.

Also the $ is not included in the value of FMTNAME.

Also sort the data by FTMNAME and START.

To see the data structure needed you should create a format using proc format and generate the CNTLOUT dataset and check how it looks.

Respected Advisor
Posts: 3,799

Re: Questions about multiple labels in PROC FORMAT

You can leave off TYPE variable and use $ in the name as the OP did.  For INFORMAT it would be @$DZ.

Super User
Posts: 19,876

Re: Questions about multiple labels in PROC FORMAT

I don't think you can get what you want with a format, since it won't expand the data to have multiple records.

You can with a SQL join though.

Super User
Posts: 5,441

Re: Questions about multiple labels in PROC FORMAT

Using format with the put function is not a multi label application.  Aggregation procedures such as means and tabulate are.

Data never sleeps
Trusted Advisor
Posts: 3,215

Re: Questions about multiple labels in PROC FORMAT

There is the multi label option with SAS Base SAS(R) 9.3 Procedures Guide, Second Edition

It is logical a doubled classification of the same variable values, avoiding the need for duplicated runs on the same data.

As the format originally is designed to recode one input to a single new output value your logical questions you started with does not make sense.

The input code look to be diagnostics that can belong to many diseases. Having many of those diagnostics not knowing the disease you could try to build a prediction model. That is total different logical process.   What are you trying to do?      

---->-- ja karman --<-----
Respected Advisor
Posts: 3,799

Re: Questions about multiple labels in PROC FORMAT

To get a Multi Label Format to "do anything" you need a multi label enabled procedure,  Means/summary, tabulate and report are it I think.

Here is example using SUMMARY that counts and uses IDGROUP to show the values of CODE in each grouping.

DATA test ;
INPUT ID CODE $;
datalines;
1 101   
2 102
3 103
4 105
;
run;
proc print;
  
run;
DATA NAME;
INPUT CODE $ DZ $;
datalines;
101 A
102 A
103 A
101 B
105 B
;
run;

DATA fmttest;
   set name;
   rename code=start dz=label;
   retain fmtname "$dz";
  
retain HLO "M";
  
run;

PROC FORMAT CNTLIN=fmttest cntlout=cntlout;
   select $dz;
   run;
proc print;
  
run;

proc summary data=test completetypes nway;
  
class code / preloadfmt mlf;
  
format code $dz.;
  
output out=test2 idgroup(out[4](code)=ocode);
   run;
proc print;
  
format ocode:;
   run;


4-5-2015 5-46-06 AM.png
Ask a Question
Discussion stats
  • 6 replies
  • 329 views
  • 0 likes
  • 6 in conversation