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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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