BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sathya66
Barite | Level 11

Hi All,

I have columns 1-n in have table  ( like COL1 COL2 COL3 COL3 COL4 COL5 COL6). I want to write like this (keep=COL(1-n). Instead of writing (keep=COL1 COL2 COL3 COL3 COL4 COL5 COL6).

because I want to select 3 columns in 1 table and 10 columns in another table.

 

data test(keep=COL1 COL2 COL3 COL3 COL4 COL5 COL6);

set have;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

when using lists you need OF keyword to concat

 

data cc(keep=COl: )
set x;
a=cat(of col: )
ru

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20

Do you mean a shorter way?

 

 

data test(keep=COL1-COL6);

set have;

run;

rajeshalwayswel
Pyrite | Level 9

data test(keep=COL:);

set have;

run;

Reeza
Super User

Variable Lists

 

data Test (keep = col1-col6);

data Test (keep = col:);

http://documentation.sas.com/?docsetId=lrcon&docsetTarget=p0wphcpsfgx6o7n1sjtqzizp1n39.htm&docsetVer...

 


@sathya66 wrote:

Hi All,

I have columns 1-n in have table  ( like COL1 COL2 COL3 COL3 COL4 COL5 COL6). I want to write like this (keep=COL(1-n). Instead of writing (keep=COL1 COL2 COL3 COL3 COL4 COL5 COL6).

because I want to select 3 columns in 1 table and 10 columns in another table.

 

data test(keep=COL1 COL2 COL3 COL3 COL4 COL5 COL6);

set have;

run;

 


 

sathya66
Barite | Level 11
Thanks,
data Test (keep = col:); this way
and also I want to concatenate the variables in a single variable .

data cc(keep=COL:);
set x;
a=cat(COL:); /*error */
run;

sathya66
Barite | Level 11
data cc(keep=COL:);
set x;
a=cat(COL:); /*error */
run;
Reeza
Super User

Please paste your code into a code box, otherwise emojis invade.

Check the link I included in my answer for examples to your new question. 

 


@sathya66 wrote:
Thanks,
data Test (keep = col:); this way
and also I want to concatenate the variables in a single variable .

data cc(keep=COL:);
set x;
a=cat(COL:); /*error */
run;


 

novinosrin
Tourmaline | Level 20

when using lists you need OF keyword to concat

 

data cc(keep=COl: )
set x;
a=cat(of col: )
ru

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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