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!
Thanks so much for your response. It works but can you please help me understand this
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.
@DivyaGadde you need to have a variable in both datasets that share something in common like an ID, date or something.
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;
Thanks so much for your response. It works but can you please help me understand this
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.
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!
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.