BookmarkSubscribeRSS Feed
cieffegi
Calcite | Level 5

Hallo,
I have a table wich contains 50 colums, 30 of which have a name which start with "ID_03_".
I would like to perform some operations only on the columns with these initial characters.
Ideally, the program wold scan the names of the colums and do 
"if the name starst then "ID_03_" perform something, otherwise skip to the next column".

is it possibile?
Thank you

2 REPLIES 2
PaigeMiller
Diamond | Level 26

You haven't really said what you want to do to these columns, so I can't give you specific instructions, but perhaps a DATA step ARRAY might be useful.

 

Example:

 

data want;
    set have;
    array x id_03_:;
    do i=1 to dim(x);
         x(i)=x(i)+1; /* Do something to these columns; in this example I add 1 to the value in each column */
    end;
    drop i;
run;
--
Paige Miller
TSR
SAS Employee TSR
SAS Employee
/* Using sashelp.mon111 which contains prefixed varnames.   
   All variables are numeric so example multiplies original by 2 .
   Select S6 as prefix where mon111 has 10 S6 variables. */
 
proc contents data=sashelp.mon111;  /* explore table */
run;
proc sql;        /* Create macro variable series of vars */
   select name
into :var1-
from sashelp.vcolumn
where libname='SASHELP' and memname='MON111' and name like 'S6%';
quit;
%put NOTE: &=sqlobs;
 
%macro x;
data work.test;
   set sashelp.mon111;
   %do i = 1 %to &sqlobs;
       new_&&var&i = &&var&i * 2;  /* e.g., create a new variable twice value of original */
   %end;
run;
proc print;
   var %do i=1 %to &sqlobs; 
          &&var&i new_&&var&i
       %end;;
run;
%mend x;
%x

 

 

Partial output, 3 of 10 variable pairs

TSR_0-1700247105752.png

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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