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-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!

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