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

Hi All,

I have a quick question about creating a variable. I have a dataset with the following information: (This data is sorted by SIC)

Firm Year      SIC      SP500

A     2001     1211     0

A     2002     1211     0

B     2001     1211     1

C     2003     1211     1

S     2001     2525     0

T     2002     2525     0

U     2002     2525     0

I want to create a new variable SP500_SIC that takes value 1 if SP500 is 1 even once for that SIC. In other words, I want the output to be like:

Firm Year      SIC      SP500     SP500_SIC

A     2001     1211     0               1

A     2002     1211     0               1

B     2001     1211     1               1

C     2003     1211     1               1

S     2001     2525     0               0

T     2002     2525     0               0

U     2002     2525     0               0

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use SQL

proc sql;

create table want as

select *, max(SP500) as SP500_SIC

from have

group by SIC;

quit;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Using PROC MEANS or PROC SUMMARY, determine the maximum value of SP500 for each SIC. This will be SP500_SIC

Next step: merge the output of PROC MEANS in with the original data.

--
Paige Miller
Reeza
Super User

Use SQL

proc sql;

create table want as

select *, max(SP500) as SP500_SIC

from have

group by SIC;

quit;

NickR
Quartz | Level 8

Assuming SP500 is a numeric variable.

proc sql;

  create table outds as select *, max(sp500) as sp500_SIC from inds group by sic order by sic,firm;

quit;

shalmali
Calcite | Level 5

Thank you guys for the prompt reply.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1362 views
  • 6 likes
  • 4 in conversation