BookmarkSubscribeRSS Feed
superbug
Quartz | Level 8

my data is like this

data test;
infile cards truncover;
input peat1 peat2;
datalines;
0 .
3 .
6 .
24 6
15 .
18 0
;

 

use the following code, I generated two new variables, peat1_ and peat2_.

 

data test_;
set test;
if 0=<peat1=<6 and peat1 ^=. then peat1_=1;

if 0=<peat2=<6 and peat2 ^=. then peat2_=1;
run;

 

Now I want to replace values of peat1 with values of peat2_, which SAS function should I use? thanks!

6 REPLIES 6
ed_sas_member
Meteorite | Level 14

Hi @superbug 

 

Something like this ??

data test_;
	set test;
	if 0=<peat1=<6 and peat1 ^=. then peat1_=1;
	if 0=<peat2=<6 and peat2 ^=. then do;
		peat2_= 1;
		peat1 = 1;
	end;
run;

 

superbug
Quartz | Level 8

 

@ed_sas_member 

thanks. using the code you suggested, the original value of peat1 changed in row 4 and row 6, which is not I wanted.

Also, there's is no difference on peat1_ and peat2_ variables using your code  and using my original code.

 

 

ed_sas_member
Meteorite | Level 14

Hi @superbug 

 

Could you please provide the expected output as it's not clear to me.

According to the IF condition you provided, there is no difference in calculation. I believe there is a mistake somewhere.

 

best,

superbug
Quartz | Level 8

@ed_sas_member 

I restructured my data. I'll consider to reach my final results in another way.

Thanks much for your time!

Oligolas
Barite | Level 11
if not missing(peat2_) then peat1=peat2_;
________________________

- Cheers -

superbug
Quartz | Level 8

@Oligolas 

Thanks much!

 

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