BookmarkSubscribeRSS Feed
Ramiro_iese
Calcite | Level 5

hi all! I am new in SAS and I am having trouble with a simple task (i can do it in another lenguage but here I do not know the syntax) 

 

I have a matrix like this 

patent class 

1           A1

2           A1 

3           B1

And I would like a dataset like this 

patent class 

1           A1

1           B1 

1           B2

2           A1 

2           B1

2           B2

3           A1

3           B1

3           B2 

 

Is it possible ? 

 

 

 

 

3 REPLIES 3
ballardw
Super User

You may have to describe more conditions if this is supposed to be an example of a bigger project. The big question is where does the value of B2 come from that is not in you starting data. Adding a value that does not exist in your current data means that we need rules about what new value(s) might be needed and when to apply them. For example you start with A1 and B1 and want a B2. Why don't you want an A2? There really does not appear to be any actual rule involved.

 

Your subject topic says "Join two datasets". But you only show one. Where is the second?

Ramiro_iese
Calcite | Level 5

Ok, I mafe a mistake in the initial post.

Assume we have two datasets of one column each.

 

patens :  1 2 3

class: A1 A2 B1 

 

I would like to have this joint db 

 

patentes class 

1               A1 

1               A2

1               B1

2               A1 

2               A2

2               B1

3               A1

3              A2

3               B1

 

 

 

thanks! 

 

ballardw
Super User

First, on this forum it is a good idea to provide your data set(s) as data step code that will create a set similar to the one you want to use. Paste the code into a text box opened on the forum with the </> icon as the main message windows here will reformat pasted text which may make code fail.

Here is one way. Note the two example data sets as code:

data one;
  input patentes;
datalines;
1
2
3
;

data two;
  input class $;
datalines;
A1
A2
B1
;

proc sql;
   create table want as
   select one.patentes,two.class
   from one,two
   ;
quit;

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 407 views
  • 0 likes
  • 2 in conversation