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.)

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