When I run the last part:
proc print data=work.Sheet1 label;
format cause1--cause6 $disease.;
label cause1 = 'Cancer name 1'
cause2 = 'Cancer name 2'
cause3 = 'Cancer name 3'
cause4 = 'Cancer name 4'
cause5 = 'Cancer name 5'
cause6 = 'Cancer name 6';
run; quit;
the work.sheet1 has the original variables without the disease names, I only see the names of diseases when running the "proc print data=work.sheet1 label"
The LABEL option only affects the display of column labels (headings). It has no effect on the data values.
Try this code to see if it gives you what you need:
options validvarname=any validmemname=extend nodate nonumber ls=max;
* Create the CNTLIN table for use with PROC FORMAT;
data work.disease_cntlin;
set work.Sheet2;
length fmtname $7 type $1 start end $3 label $256;
drop 'ICD-10 Code'n 'Disease name'n;
* Specify the required information for the format;
fmtname = 'DISEASE';
type = 'C';
start = 'ICD-10 Code'n;
end = 'ICD-10 Code'n;
label = 'Disease name'n;
run;
* Create the DISEASE format;
proc format cntlin=work.disease_cntlin; run; quit;
* Create a new table with separate columns for the diseases;
data work.Sheet1_New;
set work.Sheet1;
length disease1-disease6 $256;
disease1 = put(cause1, $disease.);
disease2 = put(cause2, $disease.);
disease3 = put(cause3, $disease.);
disease4 = put(cause4, $disease.);
disease5 = put(cause5, $disease.);
disease6 = put(cause6, $disease.);
run;
* Display the data;
title 'Labels NOT used in column headings';
proc print data=work.Sheet1_New;
label disease1 = 'Cancer name 1'
disease2 = 'Cancer name 2'
disease3 = 'Cancer name 3'
disease4 = 'Cancer name 4'
disease5 = 'Cancer name 5'
disease6 = 'Cancer name 6';
run; quit;
title 'Labels used in column headings';
proc print data=work.Sheet1_New label;
label disease1 = 'Cancer name 1'
disease2 = 'Cancer name 2'
disease3 = 'Cancer name 3'
disease4 = 'Cancer name 4'
disease5 = 'Cancer name 5'
disease6 = 'Cancer name 6';
run; quit;
Vince DelGobbo
SAS R&D
sorry, I got another errors
69 disease1 = put(cause1, $disease.);
---------
48
WARNING: Variable cause1 has already been defined as numeric.
70 disease2 = put(cause2, $disease.);
---------
48
WARNING: Variable cause2 has already been defined as numeric.
71 disease3 = put(cause3, $disease.);
---------
48
WARNING: Variable cause3 has already been defined as numeric.
72 disease4 = put(cause4, $disease.);
---------
48
WARNING: Variable cause4 has already been defined as numeric.
73 disease5 = put(cause5, $disease.);
---------
48
WARNING: Variable cause5 has already been defined as numeric.
74 disease6 = put(cause6, $disease.);
WARNING: Variable cause6 has already been defined as numeric.
I don't know what the problem is.
I just copied and pasted the complete SAS code into a new SAS session, and it worked without error.
Vince DelGobbo
SAS R&D
Hi Vince
My mistake, I got mixed up with the variable names. Your code ran just fine!!
Thank you very much for all your help
Hi Vince,
My apologies, just realized that I need the file as originally requested (attached). With the SAS code you sent me I get the ICD-10 codes in variables disease1 to 6. There should not be any entries with ICD-10 codes only the cancer name when any of the cause1 to 6 were cancer (ICD-10 codes from C00 to C97) and the rest should be blanks like the attached original file, is it possible to get this?
Thanks and sorry again.
Lalo
I think there is a mistake in your attached file. "Cancer name 4" and "Cancer name 6" should be blank for record 9 because CAUSE4 and CAUSE4 are blank.
This code assumes that any code beginning with "C" needs to have a cancer name associated with it.
options validvarname=any validmemname=extend nodate nonumber ls=max;
* Create the CNTLIN table for use with PROC FORMAT;
data work.disease_cntlin;
set work.Sheet2;
length fmtname $7 type $1 start end $3 label $256;
drop 'ICD-10 Code'n 'Disease name'n;
* Specify the required information for the format;
fmtname = 'DISEASE';
type = 'C';
start = 'ICD-10 Code'n;
end = 'ICD-10 Code'n;
label = 'Disease name'n;
run;
* Create the DISEASE format;
proc format cntlin=work.disease_cntlin; run; quit;
* Create a new table with separate columns for the diseases;
data work.Sheet1_New;
set work.Sheet1;
length i 8 disease1-disease6 $256;
drop i;
array causes(*) cause1-cause6;
array diseases(*) disease1-disease6;
do i = 1 to dim(causes);
if (upcase(causes[i]) =: 'C')
then diseases[i] = put(causes[i], $disease.);
end;
run;
* Display the data;
title 'Labels NOT used in column headings';
proc print data=work.Sheet1_New noobs style(header)=[just=c];
label disease1 = 'Cancer name 1'
disease2 = 'Cancer name 2'
disease3 = 'Cancer name 3'
disease4 = 'Cancer name 4'
disease5 = 'Cancer name 5'
disease6 = 'Cancer name 6';
run; quit;
title 'Labels used in column headings';
proc print data=work.Sheet1_New noobs label style(header)=[just=c];
label disease1 = 'Cancer name 1'
disease2 = 'Cancer name 2'
disease3 = 'Cancer name 3'
disease4 = 'Cancer name 4'
disease5 = 'Cancer name 5'
disease6 = 'Cancer name 6';
run; quit;
Vince DelGobbo
SAS R&D
Yes you're right re: record 9
SAS Code ran perfectly
Gracias
Lalo
Hi Vince,
I wonder if you can help me again?
I have another data set that I have to analyze but instead of 6 diseases now I have 25 columns for diseases (disease01-disease25). I ran the same code but got the following errors for each of the 25 diseases:
WARNING: Length of character variable disease01 has already been set. Use the LENGTH statement as the very first statement in the DATA STEP to declare the length of a character variable.
598 disease01 = put(cause01, $disease.);
---------
48
WARNING: Variable cause01 has already been defined as numeric.
I wonder what went wrong?
all your help will be apreciated it
thanks
I think that we need to see the actual code and log to debug this.
Vince DelGobbo
SAS R&D
@lalohg wrote:
One last question, how can I save the proc print output log into a SAS table when running the proc print procedure?
That does not do anything useful. proc print creates a straight hardcopy of the dataset. Putting that into a dataset is just like
data want;
set have;
run;
ok thanks
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.