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

the data step:

data Financial;
infile 'C:\books\learning\Bank.txt';
input Subj $ 1-3 DOB $ 4-13 Gender $ 14 Balance 15-21;
run;

and 3.8 below follows on the data step for reading raw data from fixed columns: 

Program 3.8: Demonstrating a FORMAT Statement
title "Listing of Financial";
proc print data=Financial;
format DOB mmddyy10.
Balance dollar11.2;
run;

produce error:

ERROR: You are trying to use the character format $ with the numeric variable Gender in data set
WORK.FINANCIAL
I appreciate your feedback

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data Financial;
infile 'C:\books\learning\Bank.txt';
informat DOB mmddyy10.;
input Subj $ 1-3 DOB  4-13 Gender $ 14 Balance 15-21;
run;
  1. Add an INFORMAT statement for DOB that specifies how it is displayed in the text file. This tells SAS how the date should be read in. SAS will then read in the date and convert it to a SAS date, which is numeric and represents the number of day from January 1, 1960. 
  2. Remove the $ in the INPUT statement by DOB to tell SAS to read it in as numeric value, not character

Then try printing it and applying a format.

 


@DJ3 wrote:

the data step:

data Financial;
infile 'C:\books\learning\Bank.txt';
input Subj $ 1-3 DOB $ 4-13 Gender $ 14 Balance 15-21;
run;

and 3.8 below follows on the data step for reading raw data from fixed columns: 

Program 3.8: Demonstrating a FORMAT Statement
title "Listing of Financial";
proc print data=Financial;
format DOB mmddyy10.
Balance dollar11.2;
run;

produce error:

ERROR: You are trying to use the character format $ with the numeric variable Gender in data set
WORK.FINANCIAL
I appreciate your feedback


 

View solution in original post

5 REPLIES 5
Reeza
Super User
ERROR: You are trying to use the character format $ with the numeric variable Gender in data set

You read in DOB as a character variable, since you included the $ sign in the INPUT statement. This means you cannot apply a date format, because that requires a numeric value. You need to modify your first data step to appropriately read the DOB as a date or you need to convert it first before applying the SAS format.
DJ3
Calcite | Level 5 DJ3
Calcite | Level 5

I appreciate the feedback from all. 

I introduce the DOB format in the input and run the code.  it worked fine, no error:

data financial;
infile 'V:\Examples\learning\Bank.txt';
input subj $ 1 - 3
@4 DOB mmddyy10.
Gender $ 14
Balance 15 -21;
run;
proc print data=Financial;
format DOB mmddyy10.
Balance dollar11.2;
run;

this worked.

Reeza
Super User
Please mark the question as answered as you know have a solution.
andreas_lds
Jade | Level 19

@DJ3 wrote:

the data step:

data Financial;
infile 'C:\books\learning\Bank.txt';
input Subj $ 1-3 DOB $ 4-13 Gender $ 14 Balance 15-21;
run;

and 3.8 below follows on the data step for reading raw data from fixed columns: 

Program 3.8: Demonstrating a FORMAT Statement
title "Listing of Financial";
proc print data=Financial;
format DOB mmddyy10.
Balance dollar11.2;
run;

produce error:

ERROR: You are trying to use the character format $ with the numeric variable Gender in data set
WORK.FINANCIAL
I appreciate your feedback


Please post the full code and log in readable form.

The code you have posted won't create the error message, because you have no statement assigning a format to the variable "Gender".

Reeza
Super User
data Financial;
infile 'C:\books\learning\Bank.txt';
informat DOB mmddyy10.;
input Subj $ 1-3 DOB  4-13 Gender $ 14 Balance 15-21;
run;
  1. Add an INFORMAT statement for DOB that specifies how it is displayed in the text file. This tells SAS how the date should be read in. SAS will then read in the date and convert it to a SAS date, which is numeric and represents the number of day from January 1, 1960. 
  2. Remove the $ in the INPUT statement by DOB to tell SAS to read it in as numeric value, not character

Then try printing it and applying a format.

 


@DJ3 wrote:

the data step:

data Financial;
infile 'C:\books\learning\Bank.txt';
input Subj $ 1-3 DOB $ 4-13 Gender $ 14 Balance 15-21;
run;

and 3.8 below follows on the data step for reading raw data from fixed columns: 

Program 3.8: Demonstrating a FORMAT Statement
title "Listing of Financial";
proc print data=Financial;
format DOB mmddyy10.
Balance dollar11.2;
run;

produce error:

ERROR: You are trying to use the character format $ with the numeric variable Gender in data set
WORK.FINANCIAL
I appreciate your feedback


 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 925 views
  • 2 likes
  • 3 in conversation