BookmarkSubscribeRSS Feed
Sam22
Calcite | Level 5
I have a data set that has variables assign_date1 to assign_date50. They are date variables but in character format
E.g sample values - 2021-05-24 ; 2021-04-15

I am trying to convert them to date using arrays and do loop. The date format that I want the values to be - 24MAY2021 ; 15APR2021. Below is the code that I am using

Data test;
Set dataset ; /*data set sample name*:

/* Existing date variables in character form*/
Array assign_date_array(50) $ 10
Assign_date1-Assign_date50;

/*Variables that would store the converted date variables*/

Array new_date_array(50)
New_date1-New_date50;

Do I =1 to 50;

New_date_array[i] = input(assign_date_array[i] , yymmdd10.);

Format new_date_array[i] date9.;
End;
Drop I;
Run;

Code runs when I exclude the format line. But as soon as I execute with format line I get error 85-232- Expecting a format name

The code runs fine when I run with individual Column name I.e not with do loop and array

3 REPLIES 3
Astounding
PROC Star

I don't think the FORMAT statement accepts an array reference.  Remove the FORMAT statement from the loop, and just code:

format Assign_date1-Assign_date50 date9.;
Tom
Super User Tom
Super User

FORMAT statements want the name(s) of the VARIABLES.  I cannot take an indirect reference to a variable since it it is not executable.  It just defines what format to attach to the vairable.

data test;
  set dataset ;
  array assign_date [50] ;
  array new_date [50] ;
  format new_date1-new_date50 date9.;
  do I =1 to 50;
    new_date[i] = input(assign_date[i] , yymmdd10.);
  end;
  drop I;
run;
ballardw
Super User

Format statement does not recognize array references.

However you can use a single format statement:

 

format new_date:  date9.;

anywhere in the data step.

The colon is a list indicator and says "use all the variable names that start with New_date".

 

You can simplify your code a little bit by using:

Array new_date(50);

That will create variables named New_date1 through New_date50 and you use New_date[i] .

 

 

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 1118 views
  • 0 likes
  • 4 in conversation