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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 5 replies
  • 342 views
  • 1 like
  • 5 in conversation