BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Mark7
Obsidian | Level 7

Hi,

I have over 400 tables named similair E_PROD_2002_01, E_PROD_2002_02, .... E_PROD_2002_20, etc.  I need to alter a column in every table, to change length char from 10 to 15. I don't want to run every single code:

 proc sql;
alter table dds.E_PROD_2002_01
modify name char(15);
quit;

 

Is there an easier way?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

A macro loop would work here. Since you state there are 400 such tables, but only show 20 table names, and I do not know what the full 400 data set names would look like, I provide code for those 20 tables. (Macro will not work for 400 without modification)

 

UNTESTED CODE

 

%macro dothis;
    %do i =1 to 20;
        proc sql;
            alter table dds.E_PROD_2002_%sysfunc(putn(&i,z2.))
            modify name char(15);
        quit;
    %end;
%mend;
%dothis

 

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

A macro loop would work here. Since you state there are 400 such tables, but only show 20 table names, and I do not know what the full 400 data set names would look like, I provide code for those 20 tables. (Macro will not work for 400 without modification)

 

UNTESTED CODE

 

%macro dothis;
    %do i =1 to 20;
        proc sql;
            alter table dds.E_PROD_2002_%sysfunc(putn(&i,z2.))
            modify name char(15);
        quit;
    %end;
%mend;
%dothis

 

--
Paige Miller
Mark7
Obsidian | Level 7

Thank you! It works! i had to add %to

%do i =1  %to 20;

Mark7
Obsidian | Level 7
Works great, thank you

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 155 views
  • 1 like
  • 2 in conversation