DATA Step, Macro, Functions and more

selecting Variables

Accepted Solution Solved
Reply
Contributor
Posts: 64
Accepted Solution

selecting Variables

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;

 


Accepted Solutions
Solution
‎04-17-2018 12:54 PM
PROC Star
Posts: 1,356

Re: selecting Variables

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


All Replies
PROC Star
Posts: 1,356

Re: selecting Variables

Do you mean a shorter way?

 

 

data test(keep=COL1-COL6);

set have;

run;

Frequent Contributor
Posts: 82

Re: selecting Variables

data test(keep=COLSmiley Happy;

set have;

run;

Super User
Posts: 22,874

Re: selecting Variables

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;

 


 

Contributor
Posts: 64

Re: selecting Variables

Thanks,
data Test (keep = colSmiley Happy; this way
and also I want to concatenate the variables in a single variable .

data cc(keep=COLSmiley Happy;
set x;
a=cat(COLSmiley Happy; /*error */
run;

Contributor
Posts: 64

Re: selecting Variables

data cc(keep=COL:);
set x;
a=cat(COL:); /*error */
run;
Super User
Posts: 22,874

Re: selecting Variables

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 = colSmiley Happy; this way
and also I want to concatenate the variables in a single variable .

data cc(keep=COLSmiley Happy;
set x;
a=cat(COLSmiley Happy; /*error */
run;


 

Solution
‎04-17-2018 12:54 PM
PROC Star
Posts: 1,356

Re: selecting Variables

when using lists you need OF keyword to concat

 

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 100 views
  • 0 likes
  • 4 in conversation