SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aexor
Lapis Lazuli | Level 10

I have a source table/dataset and I want two separate  target tables/datasets Target Table 1, Target Table 2 as below . Please advice.

 

Source table

Target Table 1

Target Table 2

ID

Name

Phone No

10

AAA

123

20

BBB

234

30

CCC

434

40

DDD

343

50

EEE

442

ID

Name

10

AAA

20

BBB

30

CCC

40

DDD

50

EEE

ID

Phone No

10

123

20

234

30

434

40

343

50

442

ID is the key column; Name and Phone No are non-key columns

 

I have tried below code and it worked too.

data source;
input id name $ ph $;
datalines;
10 AAA 123
20 BBB 234
30 CCC 434

40 DDD 343

50 EEE 442
;
run;

 

data Target1 ;
set one(drop = ph);
run;

 

data Target2;
set one(drop = name);
run;


Please suggest any other approach and also can we do it in single data step?

All suggestions are welcome.

 

Thank you.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

Try

data table1(keep= id name) table2(keep= id ph);
   set source;
run;

View solution in original post

1 REPLY 1
andreas_lds
Jade | Level 19

Try

data table1(keep= id name) table2(keep= id ph);
   set source;
run;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 1 reply
  • 866 views
  • 7 likes
  • 2 in conversation