DATA Step, Macro, Functions and more

set statment and "in="

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

set statment and "in="

[ Edited ]

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


Accepted Solutions
Solution
‎02-22-2017 06:34 AM
Super User
Posts: 19,850

Re: set statment and "in="

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


All Replies
Contributor
Posts: 22

Re: set statment and "in="

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

Super User
Posts: 19,850

Re: set statment and "in="

INDSNAME option. 

 

Data want; 

set a b INDSNAME=_source;

 

source=_source;

 

run;

Super User
Posts: 19,850

Re: set statment and "in="

Solution
‎02-22-2017 06:34 AM
Super User
Posts: 19,850

Re: set statment and "in="

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

 

 

Regular Contributor
Posts: 234

Re: set statment and "in="

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.

Contributor
Posts: 22

Re: set statment and "in="

Thanks all,

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

May be that's all it needs. I will check again.
Super User
Super User
Posts: 7,977

Re: set statment and "in="

@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.

Contributor
Posts: 22

Re: set statment and "in="

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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