BookmarkSubscribeRSS Feed
HEB1
Calcite | Level 5

Hi,

Im trying to create a variable that will constitute 4 groups.

 

if you look on the attached data, I want to create for each gvkey (equivalent to ID) a code that will show if AC variable has been changed during the years. To be specific, My 4 goups should look like that:

1. gvkeys that have only DS or/and 0,

2. gvkeys that have only DU or/and 0,

3. gvkeys that have only DI or/and 0, 

4. gvkeys that have evrything for example: DS AND DI. 

 

for each group I want to keep all the years for each gvkey.

 

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

I don't see any data? Please post sample data in the form of a datastep

HEB1
Calcite | Level 5
Thanks. this is what I tried to do


DATA NEW;
SETOLD;
by gvkey fyear;
if first.gvkey=last.gvkey and (ac=0 or ac=3) then group=3;
else
if first.gvkey=last.gvkey and(ac=0 or ac=2) then group=2;
else
if first.gvkey=last.gvkey and (ac=0 or ac=1) then group=1;
else group = 4;
run;



##- Please type your reply above this line. Simple formatting, no
attachments. -##
HEB1
Calcite | Level 5
 
ballardw
Super User

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

And show what an expected result for a sample of the data might be.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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