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

Good morning.

 

I have the following data:

 

DATE        TIC         STYPE          Name

1/1/20        MSFT         Product               Electronics

1/1/20        MSFT         Product               Computers

1/1/19        MSFT         Product               Electronics

1/1/19        MSFT         Product               Computers

1/1/20        GOOG        Foreign               Web Services

1/1/20        GOOG        Foreign               Hosting

1/1/20        GOOG        Product               Computers

 

I am looking to create a summarized table that just tell me for each data and ticker how many unique segments there are. The oupout should look like this:

 

1/1/20 MSFT   Product   2

1/1/19 MSFT   Product   2

1/1/20 GOOG   Foreign 2

1/1/20 GOOG   Product 1

 

I tried this but I am getting an error. I know I took a sum statement out but in my other code I was trying to add numbers up so that wouldn't apply here. I believe I am close!

 

proc sql;
create table temp.SEGMENTS_2 as
select TIC,
from temp.SEGMENTS_1
group by DATE, STYPE;
quit;

 

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
mklangley
Lapis Lazuli | Level 10

Try this:

proc sql;
    create table temp.SEGMENTS_2 as
    select DATE, TIC, STYPE, count(Name) as count
    from temp.SEGMENTS_1
    group by DATE, TIC, STYPE;
quit;

When you use a summary statement (like count() or sum()), any columns that you include in the SELECT statement should also be included in the GROUP BY statement. (In this case, since you want DATE, TIC, and STYPE in your ouput, they should also be in your GROUP BY list.)

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
proc freq data=have;
     tables date*tic*product/list;
run;
--
Paige Miller
mklangley
Lapis Lazuli | Level 10

Try this:

proc sql;
    create table temp.SEGMENTS_2 as
    select DATE, TIC, STYPE, count(Name) as count
    from temp.SEGMENTS_1
    group by DATE, TIC, STYPE;
quit;

When you use a summary statement (like count() or sum()), any columns that you include in the SELECT statement should also be included in the GROUP BY statement. (In this case, since you want DATE, TIC, and STYPE in your ouput, they should also be in your GROUP BY list.)

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