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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 837 views
  • 0 likes
  • 4 in conversation