Hi, I have a problem using a date with monyy5 format.
I created the from a ddmmyy10. using this code:
FECHA2=put(fecha,monyy7.); /*FECHA2 is the original date variable with ddmmyy10. format*/
MES=input(fecha2,monyy7.); /*MES is my variable for an only month year date*/
format MES monyy5.; /*Format for my new date variable*/
After that, I have a variable that only has month and year, but my problem is when I want to do a select distinct. For example, for the original date variable has two dates in april: 10/04/2017 and 18/04/2017. The new variable shows apr17 for both obs. When I run a select distinct query, it should appear only 1 obs showing apr17 (the rest of the variables are the same), but this not happens... I think internally SAS keeps the day of the date?
How could I created a date variable that only has month and year? Thanks in advance!
Yes, so dates are always held in SAS as days since a certain timepoint, regardless of format you apply to the number, you will always have the days since a timepoint number. So you code is effectively:
format fecha monyy5.;
You can put it to character and read it back in as much as you like, its not going to change the underlying number. You cannot have a month/year variable, as dates always need to be full - see above as day is needed. If you need to use only month and year, have two separate variables;
yr=year(fecha); mnth=month(fecha);
And use those, or just convert to text and group on that:
fecha2=put(fecha,monyy7.);
Yes, so dates are always held in SAS as days since a certain timepoint, regardless of format you apply to the number, you will always have the days since a timepoint number. So you code is effectively:
format fecha monyy5.;
You can put it to character and read it back in as much as you like, its not going to change the underlying number. You cannot have a month/year variable, as dates always need to be full - see above as day is needed. If you need to use only month and year, have two separate variables;
yr=year(fecha); mnth=month(fecha);
And use those, or just convert to text and group on that:
fecha2=put(fecha,monyy7.);
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.