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

Greetings folks.
I faced such kind of problem, and can't find an appropriate solution for it. Hope community could help me.

I have two variables ` x and y.
x                         y
------------------------
0                        0
1                        1
2                        2
3                        3
4                        4
5                        5
Missing             Missing
Total                  Total

 

I need to create two new variables x_all and y_all, which will include all possible combinations of x and y variables.
e.g.

 

x_all           y_all

----------------------

0                   0

0                   1

0                   2

0                   3

0                   4

0                   5

0                   Missing

0                   Total

1                   .
.

.

.

Total             Total

---------------------------------

 

Hope there are some reasonable solutions for this problem.

Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
proc sql;
create table want as
select * from (select distinct x from have), (select distinct y from have);
quit;

Assuming your input data set is called HAVE and your desired data set is called WANT the above code should work. 

 


@webart999ARM wrote:

Greetings folks.
I faced such kind of problem, and can't find an appropriate solution for it. Hope community could help me.

I have two variables ` x and y.
x                         y
------------------------
0                        0
1                        1
2                        2
3                        3
4                        4
5                        5
Missing             Missing
Total                  Total

 

I need to create two new variables x_all and y_all, which will include all possible combinations of x and y variables.
e.g.

 

x_all           y_all

----------------------

0                   0

0                   1

0                   2

0                   3

0                   4

0                   5

0                   Missing

0                   Total

1                   .
.

.

.

Total             Total

---------------------------------

 

Hope there are some reasonable solutions for this problem.

Thank you in advance.


 

View solution in original post

2 REPLIES 2
Reeza
Super User
proc sql;
create table want as
select * from (select distinct x from have), (select distinct y from have);
quit;

Assuming your input data set is called HAVE and your desired data set is called WANT the above code should work. 

 


@webart999ARM wrote:

Greetings folks.
I faced such kind of problem, and can't find an appropriate solution for it. Hope community could help me.

I have two variables ` x and y.
x                         y
------------------------
0                        0
1                        1
2                        2
3                        3
4                        4
5                        5
Missing             Missing
Total                  Total

 

I need to create two new variables x_all and y_all, which will include all possible combinations of x and y variables.
e.g.

 

x_all           y_all

----------------------

0                   0

0                   1

0                   2

0                   3

0                   4

0                   5

0                   Missing

0                   Total

1                   .
.

.

.

Total             Total

---------------------------------

 

Hope there are some reasonable solutions for this problem.

Thank you in advance.


 

webart999ARM
Quartz | Level 8
Thank you for the quick response.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 474 views
  • 0 likes
  • 2 in conversation