BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
laiguanyu001
Fluorite | Level 6

Hi,

I have a dataset that looks like this

 

A             B

fast         1

fast         1

slow        2

slow        2    

other       3

other       3

fast          4

How can I use a macro step to print an error, where values are not one to one in column a and column b? For example in the above dataset "slow"-2, "other"-3 are one to one, but "fast" -1 is not one to one.

 

For my output dataset I want:

error

fast -1 is not one to one

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Macro not needed.

 

proc sql;
    create table want as select distinct a,b from have order by a,b;
quit;

data _null_;
	set want;
	by a;
	if first.a and not last.a then
		put a= b= "is not one to one";
run;

 

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Macro not needed.

 

proc sql;
    create table want as select distinct a,b from have order by a,b;
quit;

data _null_;
	set want;
	by a;
	if first.a and not last.a then
		put a= b= "is not one to one";
run;

 

--
Paige Miller
laiguanyu001
Fluorite | Level 6

Thanks for the quick response! However this method still requires some eyeballing work. Is there a way to directly print out only the lines with error? 

PaigeMiller
Diamond | Level 26

@laiguanyu001 wrote:

Thanks for the quick response! However this method still requires some eyeballing work. Is there a way to directly print out only the lines with error? 


I just updated the code to handle this.

--
Paige Miller

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1611 views
  • 0 likes
  • 2 in conversation