BookmarkSubscribeRSS Feed
stellapersis7
Obsidian | Level 7

hi all,

i have a dataset

var1      var2

1            axe

2           bic

3           clown

4           bic-ed

 

I need to select few from var2 (around 75)and get the number of individuals having the 75 different kind of components in var2. Example: i need to have like 2000 individuals that have the 75 different components in var2. var1 is just a person id.

 i wrote this code which does not work though.

 

data 1;

set x;

keep var1 var2;

run;

proc sort data = 1 ;

by var2;

run;

proc transpose data = 1 out =2;

by var1;

var var2;

run;

 

DATA 3;

SET 2;

array DRUG(*) COL1 - COL482;

 

DM_RX =0;

do i= 1 to dim (DRUG);

if DRUG(i) IN:( 'axe', 'bic' (they are 75 which i cannot write)) THEN DM_RX=1;

END;

RUN;

please help me with the code.

thank you

 

 

1 REPLY 1
ballardw
Super User

How about walking us through an example of some steps. I am afraid this is kind of confusing:

"I need to select few from var2 (around 75)and get the number of individuals having the 75 different kind of components in var2. "

I don't know how to interpret "get the number of individuals having the different kind of components in var 2".

For one thing, how to we tell what indicates and "individual".

 

When code doesn't work show the log. I can see quickly that you are using illegal data set names. 1 and 2 are not legal as data set names. There must be at least one letter or an _ before any digits in  the names. Second, the data set has to exist before you can use it on a "data ="

 

You could combine the first couple of steps:

Proc sort data=x (keep=var1 var2) out= data1;
   by var2;
run;

The transpose, if needed (not sure if it actually is as I can't tell what you are actually doing) would look like:

proc transpose data = data1 out =data2;
   by var1;
   var var2;
run;

If you can't write a list of values, how do you expect us to write them? Do you have a document or data set with the values you expect to use? Some bits of coding are just plain routine and tedious. You could save a bit by excluding the commas in the IN operator list though. They aren't needed and spaces work just fine.

 

I also don't see any "selection" going on. At best this is writing an indicator that at least one of the values may have been found for a given Var1. Provide a larger example data set, make sure that some of the values aren't the ones you need to find, then show what the result for that example data would look like. Pick something like 3 values to look for so you can type out the result it in a reasonable amount of time.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 169 views
  • 0 likes
  • 2 in conversation