DATA Step, Macro, Functions and more

Combine the (m-dd-yy) into one variable representing the date.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Combine the (m-dd-yy) into one variable representing the date.

Hello, guys

I'm struggling in a date issue. I searched for informat date statement and did not find this type of format M-DD-YY.

here is my data

3-05-98,5.79,7.69,112.8,128,47,46.7,10.6
4-06-98,4.75,5.49,61.3,75,20,19.3,7.1
4-07-98,4.95,5.79,65.5,62,20,19.8,7.6
2-25-98,5.34,6.77,.,102,33.5,33.5,8.3

 

This my code

data limes
;
infile "/folders/myshortcuts/SASUniversityEdition/module 3/limes.txt"
firstobs=2 dsd
;
input
date fruitdia f_length fruit_Wt f_vol J_vol juice_wt peel_wt
;
proc
print data = limes
;

  Obs date fruitdia f_length fruit_Wt f_vol J_vol juice_wt peel_wt 1 2 3 4 5 6

.5.797.69112.812847.046.710.6
.4.755.4961.37520.019.37.1
.4.955.7965.56220.019.87.6
.5.346.77.10233.533.58.3
.5.446.1686.610032.031.88.7
.6.717.46164.218467.067.515.7


Thank you guys

 


Accepted Solutions
Solution
‎07-10-2017 08:54 AM
PROC Star
Posts: 326

Re: Combine the (m-dd-yy) into one variable representing the date.

this worked for me

data limes
;
infile datalines dsd ;
;
input 
date:mmddyy10. fruitdia f_length fruit_Wt f_vol J_vol juice_wt peel_wt;
format date date9.;
datalines;
3-05-98,5.79,7.69,112.8,128,47,46.7,10.6
4-06-98,4.75,5.49,61.3,75,20,19.3,7.1
4-07-98,4.95,5.79,65.5,62,20,19.8,7.6
2-25-98,5.34,6.77,.,102,33.5,33.5,8.3
;

View solution in original post


All Replies
Super User
Posts: 19,878

Re: Combine the (m-dd-yy) into one variable representing the date.

Try the informat of ANYDTDTE or MMDDYY10.  Either appeared to work fine for me.

 


Koke wrote:

Hello, guys

I'm struggling in a date issue. I searched for informat date statement and did not find this type of format M-DD-YY.

here is my data

3-05-98,5.79,7.69,112.8,128,47,46.7,10.6
4-06-98,4.75,5.49,61.3,75,20,19.3,7.1
4-07-98,4.95,5.79,65.5,62,20,19.8,7.6
2-25-98,5.34,6.77,.,102,33.5,33.5,8.3

 

This my code

data limes
;
infile "/folders/myshortcuts/SASUniversityEdition/module 3/limes.txt"
firstobs=2 dsd
;
input
date fruitdia f_length fruit_Wt f_vol J_vol juice_wt peel_wt
;
proc
print data = limes
;

  Obs date fruitdia f_length fruit_Wt f_vol J_vol juice_wt peel_wt 1 2 3 4 5 6

. 5.79 7.69 112.8 128 47.0 46.7 10.6
. 4.75 5.49 61.3 75 20.0 19.3 7.1
. 4.95 5.79 65.5 62 20.0 19.8 7.6
. 5.34 6.77 . 102 33.5 33.5 8.3
. 5.44 6.16 86.6 100 32.0 31.8 8.7
. 6.71 7.46 164.2 184 67.0 67.5 15.7


Thank you guys

 


 

Solution
‎07-10-2017 08:54 AM
PROC Star
Posts: 326

Re: Combine the (m-dd-yy) into one variable representing the date.

this worked for me

data limes
;
infile datalines dsd ;
;
input 
date:mmddyy10. fruitdia f_length fruit_Wt f_vol J_vol juice_wt peel_wt;
format date date9.;
datalines;
3-05-98,5.79,7.69,112.8,128,47,46.7,10.6
4-06-98,4.75,5.49,61.3,75,20,19.3,7.1
4-07-98,4.95,5.79,65.5,62,20,19.8,7.6
2-25-98,5.34,6.77,.,102,33.5,33.5,8.3
;
Super User
Posts: 7,866

Re: Combine the (m-dd-yy) into one variable representing the date.

[ Edited ]

The MMDDYY, DDMMYY and YYMMDD informats can all deal with single-digit days and months, so you don't need to look for a special format for dates written like that.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 120 views
  • 2 likes
  • 4 in conversation