BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8
For variae startdate I read in 2022-11-30 as text
Then i do
Startdate1=input(startdate,yymmdd10.);
Format startdate1 date9.;

How can i have startdate equals startdate1 as i need this date variable name as startdate not startdate1 but it doesnt work when i do startdate=input(startdate, yymmdd10.) strangely so i am forced to create new variable startdate1

How can i have startdate equals startdate
I try rename the date format doesnt show as 30Nov2022
5 REPLIES 5
PaigeMiller
Diamond | Level 26
data want;
    set have(rename=(startdate=old_startdate));
    startdate=input(old_startdate,yymmdd10.);
    format startdate date9.;
run;
--
Paige Miller
mkeintz
PROC Star

Your code is trying to convert a character variable to a numeric variable (date values are numeric variables) - that's a no-no.  That's why @PaigeMiller renamed the character variable STARTDATE, freeing up the desired name STARTDATE to be generated as a numeric variable.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
HeatherNewton
Quartz | Level 8
If i have many variabke like startdate i need to put in date format
How to put in all in the rename statement?
LinusH
Tourmaline | Level 20
If your data is originally in a file, you can specify the format during import.
If the data is already loaded into SAS or a database, you could probably write a macro to create the code for you.
Data never sleeps
Tom
Super User Tom
Super User

Use the RENAME statement.

data want;
  set have;
  startdate1=input(startdate,yymmdd10.);
  format startdate1 date9.;
  rename startdate=startdate_char startdate1=startdate;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 618 views
  • 1 like
  • 5 in conversation