BookmarkSubscribeRSS Feed
JenniferColeDH
Calcite | Level 5

I have a set of data that I transposed so that now all instances of results are in columns result_1, result_2, etc.  Now I need to do additional steps which include PROC SQL and I'm looking for a way to say *add all columns that start with result_*  The goal is to automate this program but I won't know how many instances of "result_" their will be for any given time period, as far as I'm aware their is no maximum.

PROC SQL;
CREATE TABLE test AS
SELECT
     T1.NAME,
     T1.DATE,
     T2.(ALL COLUMNS THAT START WITH RESULT)
FROM
     LIST1 AS T1
     INNER JOIN LIST2 AS T2
          ON T1.UID = T2.UID;
QUIT;

2 REPLIES 2
Kurt_Bremser
Super User

This is one of the limitations of SQL; you can only address columns specifically with their full name.

Make your selections with a WHERE condition before you transpose, if you need to do that (transpose) at all.

 

BIG HINT: long datasets are always better to work with than wide datasets. Write that 10.000 times, or until the message has sunk in.

FreelanceReinh
Jade | Level 19

Hi @JenniferColeDH,

 

In some cases, including the example you've shown, KEEP= and DROP= dataset options (where name prefix lists are allowed) in conjunction with the asterisk notation can overcome that limitation of (PROC) SQL:

PROC SQL;
CREATE TABLE test(drop=uid) AS
SELECT
     T1.NAME,
     T1.DATE,
     T2.*
FROM
     LIST1 AS T1
     INNER JOIN LIST2(keep=uid result:) AS T2
          ON T1.UID = T2.UID;
QUIT;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1675 views
  • 1 like
  • 3 in conversation