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

Hello team,

I need to create a dataset and I want to enter it as a date in the dataset to mimic the real dataset.

How can I change the code to get what I want:

Regards,

BlueBlue

data mbrtest;
Input Id EffeDate;
format EffeData mmddyyyy10.;
datalines;
1 12/11/2021
1 12/12/2021;
Run;

/*Date variable comes blank. How to resolve this issue? I have searched and I couldn't find any solution*/

Blue Blue
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data mbrtest;
informat EffeDate mmddyy10.;
format effeDate mmddyy10.;
Input Id EffeDate;
datalines;
1 12/11/2021
1 12/12/2021
;
Run;

 

  • Ensure the variable has the correct spelling 
  • Use an INFORMAT to specify the current format so SAS knows how to read IN the variable. 
  • Use an FORMAT to apply a format, which controls the variable appearance
  • Ensure a correct format is used, it's mmddyy - only two yy

@GN0001 wrote:

Hello team,

I need to create a dataset and I want to enter it as a date in the dataset to mimic the real dataset.

How can I change the code to get what I want:

Regards,

BlueBlue

data mbrtest;
Input Id EffeDate;
format EffeData mmddyyyy10.;
datalines;
1 12/11/2021
1 12/12/2021;
Run;

/*Date variable comes blank. How to resolve this issue? I have searched and I couldn't find any solution*/


 

View solution in original post

2 REPLIES 2
Reeza
Super User
data mbrtest;
informat EffeDate mmddyy10.;
format effeDate mmddyy10.;
Input Id EffeDate;
datalines;
1 12/11/2021
1 12/12/2021
;
Run;

 

  • Ensure the variable has the correct spelling 
  • Use an INFORMAT to specify the current format so SAS knows how to read IN the variable. 
  • Use an FORMAT to apply a format, which controls the variable appearance
  • Ensure a correct format is used, it's mmddyy - only two yy

@GN0001 wrote:

Hello team,

I need to create a dataset and I want to enter it as a date in the dataset to mimic the real dataset.

How can I change the code to get what I want:

Regards,

BlueBlue

data mbrtest;
Input Id EffeDate;
format EffeData mmddyyyy10.;
datalines;
1 12/11/2021
1 12/12/2021;
Run;

/*Date variable comes blank. How to resolve this issue? I have searched and I couldn't find any solution*/


 

ballardw
Super User

The log should have told you most of the problems:

11   data mbrtest;
12   Input Id EffeDate;
13   format EffeData mmddyyyy10.;
                     -----------
                     484
NOTE 484-185: Format MMDDYYYY was not found or could not be loaded.

14   datalines;

NOTE: Variable EffeData is uninitialized.
NOTE: Invalid data for EffeDate in line 15 3-12.
RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+--
15         1 12/11/2021
Id=1 EffeDate=. EffeData=. _ERROR_=1 _N_=1
NOTE: Invalid data for EffeDate in line 16 3-12.
16         1 12/12/2021
Id=1 EffeDate=. EffeData=. _ERROR_=1 _N_=2
NOTE: The data set WORK.MBRTEST has 2 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


17   ;
18   Run;

First: do not place the ; at the end of datalines on a line with data, that causes an error.

Your code did not provide any instructions on how to read Effedate so SAS assumes it is a simple numeric value. The / in the value means the values are not simple numbers and generate invalid data messages.

The log tells you that the name of the Format you attempted to use is invalid. (Hint: None of the SAS supplied date formats/informats use YYYY in the name. Or at least I haven't see one yet.)

The note that Effedata is uninitialized should have been a clue that you have a spelling issue.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 426 views
  • 2 likes
  • 3 in conversation