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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 1091 views
  • 0 likes
  • 4 in conversation