BookmarkSubscribeRSS Feed
MisterJenn
Fluorite | Level 6

I am trying to apply the smoking and treatment format to the smoker and treatment variable. 

proc freq data=fit1;
table smoke tx_status;
format smoke CSfmt. tx_status txfmt.;
run;
79   libname hw4 '\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Assignment 4';
NOTE: Libref HW4 was successfully assigned as follows:
      Engine:        V9
      Physical Name: \\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Assignment 4
80   data fit1;
81   set hw4.fit1;
82   run;

NOTE: There were 5813 observations read from the data set HW4.FIT1.
NOTE: The data set WORK.FIT1 has 5813 observations and 14 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds


83   proc format;
84   value $CSfmt 1 = 'Current Smokers' 0 = 'Nonsmokers';
NOTE: Format $CSFMT is already on the library WORK.FORMATS.
NOTE: Format $CSFMT has been output.
85   value $txfmt 1 = "treatment" 0 = "Placebo";
NOTE: Format $TXFMT is already on the library WORK.FORMATS.
NOTE: Format $TXFMT has been output.
86   value $bmifmt 25-HIGH ="overweight" LOW -< 25="normal";
NOTE: 25 is a numeric field and a character format is defined.
NOTE: Format $BMIFMT is already on the library WORK.FORMATS.
NOTE: Format $BMIFMT has been output.
87   value $bmigrp LOW -< 18= 'underweight' 18 - 25 = 'normal' 25 <- HIGH = 'normal';
NOTE: 18 is a numeric field and a character format is defined.
NOTE: Format $BMIGRP is already on the library WORK.FORMATS.
NOTE: Format $BMIGRP has been output.
88   run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


89   proc means data =fit1 p25;

NOTE: There were 5813 observations read from the data set WORK.FIT1.
NOTE: PROCEDURE MEANS used (Total process time):
      real time           0.04 seconds
      cpu time            0.04 seconds


90   proc format;
91   value cobmdfmt 0.5450000-HIGH = 'Above';
NOTE: Format COBMDFMT is already on the library WORK.FORMATS.
NOTE: Format COBMDFMT has been output.
92   value blbmdfmt LOW -< 0.5420000 = 'less';
NOTE: Format BLBMDFMT is already on the library WORK.FORMATS.
NOTE: Format BLBMDFMT has been output.
93   run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


94   data fit1tmp;
95   set hw4.fit1;
96   run;

NOTE: There were 5813 observations read from the data set HW4.FIT1.
NOTE: The data set WORK.FIT1TMP has 5813 observations and 14 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds


97   proc print data=fit1(obs=5);
98   var dob dov;
99   format dob dov mmddyy10.;
100  run;

NOTE: There were 5 observations read from the data set WORK.FIT1.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


101  proc freq data=fit1;
102  table smoke tx_status;
103  format smoke $CSfmt. tx_status $txfmt.;
ERROR: You are trying to use the character format $TXFMT with the numeric variable tx_status in data
       set WORK.FIT1.
104  run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE FREQ used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
5 REPLIES 5
MisterJenn
Fluorite | Level 6

I am trying to figure out why I keep getting this error message. I thought I applied the formats to me variables. However the error message is saying it cannot be found. What did I do wrong?

 

libname hw4 '\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Assignment 4';
data fit1;
set hw4.fit1;
run;
proc format; 
value CSfmt 1 = 'Current Smokers' 0 = 'Nonsmokers';
value txfmt 1 = "treatment" 0 = "Placebo";
value $bmifmt 25-HIGH ="overweight" LOW -< 25="normal";
value $bmigrp LOW -< 18= 'underweight' 18 - 25 = 'normal' 25 <- HIGH = 'normal';
run;
proc means data =fit1 p25; 
proc format; 
value cobmdfmt 0.5450000-HIGH = 'Above';
value blbmdfmt LOW -< 0.5420000 = 'less'; 
run;
data fit1tmp;
set hw4.fit1;
run;
proc print data=fit1(obs=5);
var dob dov;
format dob dov mmddyy10.;
run;
 proc means data = fit1;
format smoker CSfmt. tx_status txfmt.;
run; 
proc freq data=fit1; 
table bmi;
format bmi bmifmt.;
run;
NOTE: Libref HW4 was successfully assigned as follows:
      Engine:        V9
      Physical Name: \\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Assignment 4
73   data fit1;
74   set hw4.fit1;
75   run;

NOTE: There were 5813 observations read from the data set HW4.FIT1.
NOTE: The data set WORK.FIT1 has 5813 observations and 14 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds


76   proc format;
77   value CSfmt 1 = 'Current Smokers' 0 = 'Nonsmokers';
NOTE: Format CSFMT is already on the library WORK.FORMATS.
NOTE: Format CSFMT has been output.
78   value txfmt 1 = "treatment" 0 = "Placebo";
NOTE: Format TXFMT is already on the library WORK.FORMATS.
NOTE: Format TXFMT has been output.
79   value $bmifmt 25-HIGH ="overweight" LOW -< 25="normal";
NOTE: 25 is a numeric field and a character format is defined.
NOTE: Format $BMIFMT is already on the library WORK.FORMATS.
NOTE: Format $BMIFMT has been output.
80   value $bmigrp LOW -< 18= 'underweight' 18 - 25 = 'normal' 25 <- HIGH = 'normal';
NOTE: 18 is a numeric field and a character format is defined.
NOTE: Format $BMIGRP is already on the library WORK.FORMATS.
NOTE: Format $BMIGRP has been output.
81   run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


82   proc means data =fit1 p25;

NOTE: There were 5813 observations read from the data set WORK.FIT1.
NOTE: PROCEDURE MEANS used (Total process time):
      real time           0.04 seconds
      cpu time            0.03 seconds


83   proc format;
84   value cobmdfmt 0.5450000-HIGH = 'Above';
NOTE: Format COBMDFMT is already on the library WORK.FORMATS.
NOTE: Format COBMDFMT has been output.
85   value blbmdfmt LOW -< 0.5420000 = 'less';
NOTE: Format BLBMDFMT is already on the library WORK.FORMATS.
NOTE: Format BLBMDFMT has been output.
86   run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


87   data fit1tmp;
88   set hw4.fit1;
89   run;

NOTE: There were 5813 observations read from the data set HW4.FIT1.
NOTE: The data set WORK.FIT1TMP has 5813 observations and 14 variables.
NOTE: DATA statement used (Total process time):
      real time           0.10 seconds
      cpu time            0.01 seconds


90   proc print data=fit1(obs=5);
91   var dob dov;
92   format dob dov mmddyy10.;
93   run;

NOTE: There were 5 observations read from the data set WORK.FIT1.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


94    proc means data = fit1;
95   format smoker CSfmt. tx_status txfmt.;
96   run;

NOTE: There were 5813 observations read from the data set WORK.FIT1.
NOTE: PROCEDURE MEANS used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds


97   proc freq data=fit1;
98   table bmi;
99   format bmi bmifmt.;
ERROR: The format BMIFMT was not found or could not be loaded.
100  run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE FREQ used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
Tom
Super User Tom
Super User

You need to define NUMERIC formats if you want to use them with numeric values.

Also the last label for the second looks wrong.  Or if you actually did only want two labels just define two ranges, not three.

value bmifmt 25-HIGH ="overweight" LOW -< 25="normal";
value bmigrp LOW -< 18= 'underweight' 18 - 25 = 'normal' 25 <- HIGH = 'overweight';

 

ballardw
Super User

Did you not read any of the responses to your previous basically identical post https://communities.sas.com/t5/New-SAS-User/Custom-format-statement-error/m-p/836844

 

Run PROC CONTENTS on your data set.

ANY of the variables reported as TYPE= NUM cannot use any format whose name starts with $.

Any of the variables reported as TYPE=Char cannot use any format whose name does not start with $.

 

$ in the format name means that the format is intended to apply to Character values. You have to know the type of your variables before applying any format.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 871 views
  • 0 likes
  • 4 in conversation