BookmarkSubscribeRSS Feed
VarunD
Obsidian | Level 7

I am reading a SAS data set in PROC SQL and using COUNT. It is giving me one extra count - I suspect it is counting the header as well. How do I fix this ?

Here's the code:


PROC SQL;
CREATE TABLE Nat_1 AS
SELECT DISTINCT Loc_Nat,
COUNT(MBR_ID) AS Other
FROM Employee4
WHERE Loc_Nat = 'National' 
QUIT;

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

And how will we tell from that?  Provide test data in the form of a datastep!

The sql looks wrong to me, you are using distinct, and counting with a where clause.  Seems to be counter intuitive.

proc sql;
  create table nat_1 as
  select loc_nat,
         count(mbr_id) as other
  from   employee4
  group by loc_nt
  having loc_nat="National";
quit;
VarunD
Obsidian | Level 7
I am sorry, I found the issue with the data. Thanks for your response!
novinosrin
Tourmaline | Level 20

Please post a sample of what you 'HAVE' and what your desired output 'WANT'

VarunD
Obsidian | Level 7
Sorry the issue was with data. I found it. Thanks!
ballardw
Super User

@VarunD wrote:

I am reading a SAS data set in PROC SQL and using COUNT. It is giving me one extra count - I suspect it is counting the header as well. How do I fix this ?

Here's the code:


PROC SQL;
CREATE TABLE Nat_1 AS
SELECT DISTINCT Loc_Nat,
COUNT(MBR_ID) AS Other
FROM Employee4
WHERE Loc_Nat = 'National' 
QUIT;


The "header" would only get counted if you imported the header as a value for the variables.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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