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

Hello,

 

Quick question for you guys: I basically want to create a macro variable called syserr1 that if greater than 0 will give me an error message in an other code.

Now, the code below creates my macro variable no problem, I was just wondering if it was possible to create ONLY one macro variable in my procedure instead of 3? (AKA no need to create &nobs and &nuniqid

 

proc sql;
	select count(distinct ID) as Nuniq, count(*) as Nobs, calculated Nobs - calculated Nuniq as diff 
	into :nobs, :nuniqid, :syserr1
		from Have
	;
quit;

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
proc sql;
	select count(*) - count(distinct ID) into :syserr1
		from Have
	;
quit;

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I really don't understand your question.  If you only want one macro variable, then only select one data item:

proc sql;
  select count(distinct ID) 
  into :nobs
  from Have;
quit;

 

x2PSx
Calcite | Level 5
The macro variable that I need is the difference between the unique observations and the total number of observations. My third variable in the select clause creates this variable and is the only one that I need.
Reeza
Super User
proc sql;
	select count(*) - count(distinct ID) into :syserr1
		from Have
	;
quit;
x2PSx
Calcite | Level 5
I knew it was gonna be easy... Wow. Thank you very much for response time, Good day to you!

CFC_SAS_Communities_400x225.jpgCFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 4 replies
  • 8419 views
  • 0 likes
  • 3 in conversation