02-26-2015 11:39 AM
I have three separate variables: day, month, and year.
I would like to construct a variable that retains the first occurrence of a certain value, and then outputs the date of the occurrence in the form of MM-DD-YYYY.
Does anyone know how I would go about this?
Much thanks in advance!!
02-26-2015 12:51 PM
Thanks! Bear with me, I am new to sas:
I did see this on another thread:
Well, it seems working for me, please see:
informat date $80.;
input date ;
format _date mmddyy10.;
My suspicion is that you can't just convert char to numeric under the SAME variable name. You have to create another variable to the job, and if you want your old name back, you can always do it using date step options like: drop= rename=.
However, without seeing your code and log, I can be totally off on this one.
However my problem is my date, year, and month are each a different variable, it is not together as in the example above. In the link you gave me, it seems to require the user to input the date manually.
02-26-2015 12:37 PM
I have done this 2 ways:
a. use %let = variablename (such as year, month day) and then referencing them as macro variables
b. use a data step to set the variables and then referencing them as macro variables
Using method a:
%let rundate = %SYSFUNC(today(),yymmddn8.);
%let runhour = %SYSFUNC(HOUR(%SYSFUNC(time(), MINUTE.)), Z2.);
%let runmin = %SYSFUNC(MINUTE(%SYSFUNC(TIME(), MINUTE.)), Z2.);
then set variable to use the above values:
Note the extra period after each macro variable when it is referenced using &.
Using method b:
Create a table that gets the "rundate":
CREATE TABLE WORK.GET_REPORT_RUNDATE AS
SELECT DISTINCT /* REPORT_RUNDATE */
(DATETIME()) FORMAT=NLDATM30. AS REPORT_RUNDATE
FROM WORK.GET_ALL_TESTS t1;
Then use a data step to break apart the datetime:
rundate = datepart(report_rundate);
year = year(rundate);
month = month(rundate);
runtime = timepart(report_rundate);
hour = hour(runtime);
minute = minute(runtime);
format month z2.;
format hour z2.;
format minute z2.;
charmonth = put(month, z2.);
charhour = put(hour, z2.);
charmin = put(minute, z2.);
reportrundate = year||charmonth||'_'||charhour||charmin;
Then, reference those macro variables :
02-26-2015 01:27 PM
do you know how I would put it in my code? so far I have
*what command do I put here?* sasdate=mdy(CALL_MONTH,CALL_DAY,CALL_YEAR);
format sasdate mmddyyD10.;
02-26-2015 03:41 PM
Convert each of the fields to a number:
If the columns are no wider than the numbers then you don't need the left function.
02-26-2015 03:44 PM
I figured out what I was doing wrong...I was using the wrong data set to run the proc freq. Sorry about the silly mistake. It works now..thanks everybody for your help!!!