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

Hi,

 

I am struggling to combine datasets with unequal observations in SAS and no common variables between them.

Example: I have a dataset A  and Dataset B and will be needing data set c which should look something like follows. Is there any  I could do this? When there are no common variables in dataset A and B and not having equal observations in those datasets.

  

Data set A:                                             Dataset  B                                    Dataset C

ID NAME CODE                           begin            end                           ID             Name            Code           begin          end

1    X          123                               120               130                           1                x                   123              120           30

2    Y           125                               500               600                          2                y                   125              500           600

3    Z           567                                                                                    3                z                    567             120            30

4    A           783                                                                                    4               A                    783             500            600

 

Thanks very much!

1 ACCEPTED SOLUTION

Accepted Solutions
DivyaGadde
Fluorite | Level 6

Thanks so much for your response. It works but can you please help me understand this

View solution in original post

8 REPLIES 8
Reeza
Super User
You just want to repeat the records until the end?
Data set C is what you need exactly?

Does this need to expand to more records in Data set B or will you have only 2 records?
DivyaGadde
Fluorite | Level 6

You're right I want to repeat the records until the end. I have 30000 variables in dataset A and 32 observations in dataset B. So I want a dataset C with all the variables in dataset A and repeats of all the 32 variables in dataset B till the end.

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

@DivyaGadde you need to have a variable in both datasets that share something in common  like an  ID, date or something.

Tom
Super User Tom
Super User

Not really any type of merge.  Looks like you want to cycle through the observations in B.

data want;
  set a;
  p=1+mod(_n_-1,nobs);
  set b point=p nobs=nobs;
run;

What happens if A has fewer observations than B?  What do want to do then?  Would you want to do the same type of cycle through A?

data want;
  if _n_ > max(nobs1,nobs2) then stop;
  p1=1+mod(_n_-1,nobs1);
  p2=1+mod(_n_-1,nobs2);
  set a point=p1 nobs=nobs1;
  set b point=p2 nobs=nobs2;
run;
DivyaGadde
Fluorite | Level 6

Thanks so much for your response. It works but can you please help me understand this

Reeza
Super User
Mark the correct answer as the Solution please, not your own comment.
Tom
Super User Tom
Super User

What part don't you understand?  The MOD() function?  The POINT= option? The NOBS= option? Look at the man pages for the MOD() function and the SET statement.

DivyaGadde
Fluorite | Level 6

Hi Sir!

 

I really appreciate your help with the previous question. I've got another problem and would like to use the help and advice of the SAS experts here.

I have multiple CSV data files with the same set of variables in every raw data file (also all the files are present in the same directory). I would like to import all of them once and create a new SAS.

 

Thanks for all your help in Advance!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 8 replies
  • 2130 views
  • 2 likes
  • 4 in conversation