BookmarkSubscribeRSS Feed
SasPro
Calcite | Level 5

Hi,

I have 2 variables var1 and var2, Var1 is a grouping variable and var2 is reference variable. Here i want to create new variable called Required which takes values from Var2 from the group(var1) and should copy to new variable (Required).

I tried with first. and last. My logic is not working for this data. as u can see then values may lie middle of the group.

And in the third group you can see we have 2 values 90696x22 and GWYSGNx1afdMxcVGQb2x19, in this case i want to GWYSGNx1afdMxcVGQb2x19 to new variable. Hint is i want to copy only those values from var2 who's value is ending with "x19".

It will be great full for your support.

Thanks

Var1Var2Required
0000000000000000001800008640326AHmas$ZYcNhrbd30NniiOc6x19
0000000000000000001800008640326AHmas$ZYcNhrbd30NniiOc6x19
0000000000000000001800008640326AHmas$ZYcNhrbd30NniiOc6x19Hmas$ZYcNhrbd30NniiOc6x19
0000000000000000001800008640326AHmas$ZYcNhrbd30NniiOc6x19Hmas$ZYcNhrbd30NniiOc6x19
0000000000000000001800008640326AHmas$ZYcNhrbd30NniiOc6x19
0000000000000000001800008640326AHmas$ZYcNhrbd30NniiOc6x19
0000000000000000001800008640326AHmas$ZYcNhrbd30NniiOc6x19
0000000000000000001800008640326AHmas$ZYcNhrbd30NniiOc6x19
0000000000000000001800008640326AHmas$ZYcNhrbd30NniiOc6x19
00033F83EF8F58FB6AF3ACA6FFFFFFFFOmrsjLWkNxioc7M1Oj6$bex19OmrsjLWkNxioc7M1Oj6$bex19
00033F83EF8F58FB6AF3ACA6FFFFFFFFOmrsjLWkNxioc7M1Oj6$bex19
00033F83EF8F58FB6AF3ACA6FFFFFFFFOmrsjLWkNxioc7M1Oj6$bex19
00033F83EF8F58FB6AF3ACA6FFFFFFFFOmrsjLWkNxioc7M1Oj6$bex19
00033F83EF8F58FB6AF3ACA6FFFFFFFFOmrsjLWkNxioc7M1Oj6$bex19
001EE2E43C3711D1A0193A08FFFFFFFF90696x22EU$GWYSGNx1afdMxcVGQb2x19
001EE2E43C3711D1A0193A08FFFFFFFFEU$GWYSGNx1afdMxcVGQb2x19
001EE2E43C3711D1A0193A08FFFFFFFF90696x22EU$GWYSGNx1afdMxcVGQb2x19
001EE2E43C3711D1A0193A08FFFFFFFFEU$GWYSGNx1afdMxcVGQb2x19
001EE2E43C3711D1A0193A08FFFFFFFFEU$GWYSGNx1afdMxcVGQb2x19
001EE2E43C3711D1A0193A08FFFFFFFFEU$GWYSGNx1afdMxcVGQb2x19EU$GWYSGNx1afdMxcVGQb2x19
9FB83E1BFC68D743250F4D9AFFFFFFFF05qOOZmsNxha0cM1Oj6$bex19
9FB83E1BFC68D743250F4D9AFFFFFFFF05qOOZmsNxha0cM1Oj6$bex19
9FB83E1BFC68D743250F4D9AFFFFFFFF05qOOZmsNxha0cM1Oj6$bex19
9FB83E1BFC68D743250F4D9AFFFFFFFF05qOOZmsNxha0cM1Oj6$bex19
9FB83E1BFC68D743250F4D9AFFFFFFFF05qOOZmsNxha0cM1Oj6$bex19
A0012E3CA47467275AD0EC12FFFFFFFF05qOOZmsNxha0cM1Oj6$bex1905qOOZmsNxha0cM1Oj6$bex19
3 REPLIES 3
esjackso
Quartz | Level 8

Can you post the actual code you used? The sort and data step should be enough.

EJ

esjackso
Quartz | Level 8

Sorry just saw that this was a duplicate post ... EJ

Mit
Calcite | Level 5 Mit
Calcite | Level 5

Following your logic I think the following should not have anything the Required column in your result

9FB83E1BFC68D743250F4D9AFFFFFFFF

9FB83E1BFC68D743250F4D9AFFFFFFFF

9FB83E1BFC68D743250F4D9AFFFFFFFF

9FB83E1BFC68D743250F4D9AFFFFFFFF

9FB83E1BFC68D743250F4D9AFFFFFFFF

Try this code

proc sort data=have out=have1 nodupkey;

by var1 var2;

run;

data have1;

set have1;

where var2 ne '';

run;

data have1;

set have1;

where index(var2, 'x19')> 0;

run;

proc sort data=have;

by var1;

proc sort data=have1 out=have2(rename=(var2=Required)) ;

by var1;

data want;

merge have(in=a) have2(in=b);

by var1;

if a;

run;

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