BookmarkSubscribeRSS Feed
Neil_C
Calcite | Level 5

I want to combine these two steps below into one by creating the variable Value within the Master dataset itself, without using proc sort to get rid of the duplicates. Is there multiple ways of doing that? 

proc sort data=master out=test nodupkey;

where prefix = 'ABC';

by id group;

run;

data test;

set test;

value = 1.0;
run;

5 REPLIES 5
Steelers_In_DC
Barite | Level 11

Here you go, this way the 1.0 is a character.  If you want it to be a number remove the quotes:

data master;

infile cards dsd;

input id$ group$ prefix$;

cards;

100,abc,ABC

200,abc,123

300,abc,123

400,qwe,123

500,qwe,ABC

;

run;

proc sql;

create table test as

select distinct *,'1.0' as Value

from master

where prefix = 'ABC'

order by id,group;

Neil_C
Calcite | Level 5

Thanks Mark for the proc sql method. I have more variables in this file where I was aiming to create different values for Value based on multiple if ... then else conditions. So it would be nice to change the master file instead of creating another file 'test'. Is there a similar program like below?

So the program would be something like

data master;

set master;

if condition1 then value = 2;

else if condition2 then value = 3;

else if ......;

....;

else if prefix  = 'ABC' .....  then value = 1;

run;

Steelers_In_DC
Barite | Level 11

I think it would be best to provide a sample of the data you have and give more information for what you want.

Neil_C
Calcite | Level 5

data master;

infile cards dsd;

input id$ group$ prefix$ var1$ var2;

cards;

100,abc,ABC,F,11

100,abc,123,F,11

200,abc,123,H,12

300,abc,123,F,11

400,qwe,123,H,13

500,qwe,ABC,F,15 ;

run;

data master;

set master;

if prefix  = 'ABC'  then value = 1; * need to insert appropriate program here that scans through rows vertically for each combination of id & group, and labels Value as 1 for row containing ABC and ignores other rows. Only one row should have a value of 1 if there are multiple mentions of ABC in prefix for each id-group combination.

For example, for 1st two rows combination of id-group (100 & abc) mentioned above, only 1st row gets assigned Value as 1 and next row as missing. For the rest of rows not having prefix values of ABC the program is shown below.

Hope this makes sense ;

else if var1 = 'F' and var2 =11 then value = 2;

else if var1 = 'H' and var2 =11 then value = 3;

else if ......;

else if ....;

run;

Ksharp
Super User

Hash Table can do that.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 941 views
  • 3 likes
  • 3 in conversation