SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
J_CKY
Obsidian | Level 7

Hi,

 

I would like to combine 2 datasets without sorting them, just add a flag to identify where each row coming from.

 

I have put together the following code but of course it won't work as (in=a) style syntax in not valid for set statement. A simple solution would be great and much appreciated

	data output;
	set table_a  (in=a)  
	    table_b (in=b);
	
	format from $1.;
	if a then from='A' ; 
          else if b then from='B';

	run;

 

 

Thanks in advance
Jack

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

There's something else wrong with your code - IN is valid in SET. 

I would check your log carefully and ensure your data matches what you expect. 

 

https://support.sas.com/documentation/cdl/en/ledsoptsref/69751/HTML/default/viewer.htm#n1p1o2dsuc465...

 

 

View solution in original post

8 REPLIES 8
J_CKY
Obsidian | Level 7

I have added a line

set ... ;

by ID;

format ... ;

and it seems working fine.  But I am not sure if that works because of the dataset has been sorted or not.

 

 

Can someone give me a firm answer? Much appreciated.

 

Thanks,
Jack

Reeza
Super User

INDSNAME option. 

 

Data want; 

set a b INDSNAME=_source;

 

source=_source;

 

run;

Reeza
Super User

There's something else wrong with your code - IN is valid in SET. 

I would check your log carefully and ensure your data matches what you expect. 

 

https://support.sas.com/documentation/cdl/en/ledsoptsref/69751/HTML/default/viewer.htm#n1p1o2dsuc465...

 

 

gamotte
Rhodochrosite | Level 12

hello,

 

I don't see any reason why your program shouldn't work (except maybe the use of

the reserved word "FROM" for a variable id but that should not be a problem here).

 

 

I ran it without error.

J_CKY
Obsidian | Level 7
Thanks all,

I think it works after I added the "by statement"

May be that's all it needs. I will check again.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

@Reeza has the correct idea.  What Iwould ask is two questions:

What does "combine two datasets", do you mean set one under the other as combine can mean various things.

Also, what does your data actually contain which a) requires multiple datasets which are the same, and b) has some informatioon in the dataset name which is not in the data?  Sounds like a bad setup to start up with.

J_CKY
Obsidian | Level 7

Thanks for all the input. I think it was just me wrote some crap code and failed the first time round. 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1970 views
  • 0 likes
  • 4 in conversation