hello,
I am trying to put data in a new format and i keep on getting an error/warning message saying that the format cannot be found
this is my data year looking like
this is what proc contents shows me
36263539
Dob | Char | 10 | $EAR. | ||
bmdob | Num | 8 | MMDDYY10. | bmdob | |
hepbdate | Char | 10 | $10. | $10. | hepbdate |
hpdate | Char | 10 | $EAR. |
and then I am trying to convert it to show just a year using this code
data work.vitaldob;
set new.step2;
Dob=put(bcdob,MMDDYYS10. ) ;
Format dob year. ;
hpdate=put(hepbdate,MMDDYYs10.);
format hpdate year.;
run;
but I keep on getting this error
please help
Updated answer. Looks like BCBOB is the label for BMBOB which is very confusing.
data work.vitaldob;
set new.step2;
Dob=bmdob ;
Format dob year. ;
hpdate=input(hepbdate,yymmdd10.);
format hpdate year.;
run;
data work.vitaldob;
set new.step2;
Dob=bcdob ;
Format dob year. ;
hpdate=input(hepbdate,yymmdd10.);
format hpdate year.;
run;
@Cooksam13 wrote:
hello,
I am trying to put data in a new format and i keep on getting an error/warning message saying that the format cannot be found
this is my data year looking like
this is what proc contents shows me
36263539
Dob Char 10 $EAR. bmdob Num 8 MMDDYY10. bmdob hepbdate Char 10 $10. $10. hepbdate hpdate Char 10 $EAR.
and then I am trying to convert it to show just a year using this code
data work.vitaldob;
set new.step2;
Dob=put(bcdob,MMDDYYS10. ) ;
Format dob year. ;
hpdate=put(hepbdate,MMDDYYs10.);
format hpdate year.;
run;but I keep on getting this error
72 Format dob year. ;_____484NOTE 484-185: Format $YEAR was not found or could not be loaded.73 hpdate=put(hepbdate,MMDDYYs10.);__________484NOTE 484-185: Format $MMDDYYS was not found or could not be loaded.74 format hpdate year.;_____484NOTE 484-185: Format $YEAR was not found or could not be loaded.please help
thanks for this but I still get the same error/warning
You have a varaible BCDOB, but you don't show that variable in PROC CONTENTS. I assume it must be character, is it, according to PROC CONTENTS?
sorry for this mix up
24
bcdob | Num | 8 | MMDDYY10. | bcdob |
why not just use year function? year=year(bcdob). that extracts the year from a SAS date.
You are getting these errors because some variables are character. THere are no date or time formats for character variables, and you cannot use date or time functions on character variables. This is why I want to see the ENTIRE output from PROC CONTENTS.
Okay, show us the ENTIRE output from PROC CONTENTS. Do not select parts to show us and not show us other parts. Make sure you show us the stuff at the top which indicates the name of the data set that you are running PROC CONTENTS on.
proc contents data = work.vitaldob;
run; quit;
# Variable Type Len Format Informat Label36243539
Dob | Char | 10 | $MDDYYS10. | ||
bcdob | Num | 8 | MMDDYY10. | bcdob | |
hepbdate | Char | 10 | $10. | $10. | hepbdate |
hpdate | Num | 8 |
I can only show this information for security reasons
You already have a DOB variable that is CHAR. So you cannot make a new one that is numeric.
Either make a NEW variable.
new_dob = year(bcdob);
Or if you are ok with a character DOB variable use PUT() to convert the date in BCDOB into a four digit string with the year value. And remove that attempt to attach the numeric format to DOB. There is no need to attach a format to a character variable. SAS already know how to display character string just fine without any special instructions.
dob = put(bcdob,year4.);
format dob;
I suspect that in your attempts at various solutions you have overwritten your input.
Try going back to the original data and starting over.
Updated answer. Looks like BCBOB is the label for BMBOB which is very confusing.
data work.vitaldob;
set new.step2;
Dob=bmdob ;
Format dob year. ;
hpdate=input(hepbdate,yymmdd10.);
format hpdate year.;
run;
Bottom line: This message appears when you try to apply the year. format to a character variable. It can only be used for a numeric variable. Check your data.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.