BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
subrat1
Fluorite | Level 6

I wants to create purchase date based on quantity being purchased on any month, similarly i also wants to create a selling date if the quantity is either sold or if not sold then the last month as selling date as shown in below table as example.

 

Mutual FundQuantity_201801Quantity_201802Quantity_201803Quantity_201804Quantity_201805Quantity_201806Quantity_201807Purchase DateSelling Date
3470040000400005000000201803201806
21806000500008000900090009000201802201807
32620000200002000020000000201801201805
4450000700700700201805201807
1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

please try the below code and test it

 

 

data have;
input Mutual_Fund Quantity_201801 Quantity_201802 Quantity_201803 Quantity_201804 Quantity_201805;
cards;
347 0 0 40000 40000 50000
;

data want;
set have;
array vars(*) Quantity_201801 Quantity_201802 Quantity_201803 Quantity_201804 Quantity_201805;
array vars2(*)$100. var1 - var5;
do i = 1 to dim(vars);
if vars(i)>0 then vars2(i)=scan(vname(vars(i)),2,'_');
end;
product_date=input(coalescec(of var1-var5),best.);
drop var: i;
run;
Thanks,
Jag

View solution in original post

3 REPLIES 3
subrat1
Fluorite | Level 6

I want to identify the purchasing date based on Quantity amount being present, and then take suffix of the column as date as shown below.

Here in below example i want to create a column name Purchase date where date value is reflecting the moment customer purchase any quantity.

 

Mutual FundQuantity_201801Quantity_201802Quantity_201803Quantity_201804Quantity_201805Purchase Date
34700400004000050000201803
218060005000080009000201802
3262000020000200002000020000201801
4450000700201805
Jagadishkatam
Amethyst | Level 16

please try the below code and test it

 

 

data have;
input Mutual_Fund Quantity_201801 Quantity_201802 Quantity_201803 Quantity_201804 Quantity_201805;
cards;
347 0 0 40000 40000 50000
;

data want;
set have;
array vars(*) Quantity_201801 Quantity_201802 Quantity_201803 Quantity_201804 Quantity_201805;
array vars2(*)$100. var1 - var5;
do i = 1 to dim(vars);
if vars(i)>0 then vars2(i)=scan(vname(vars(i)),2,'_');
end;
product_date=input(coalescec(of var1-var5),best.);
drop var: i;
run;
Thanks,
Jag
ChrisNZ
Tourmaline | Level 20

You've been around for a while now @subrat1 

Please provide the input data as ready-to-run code (a data step or proc sql).

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 800 views
  • 0 likes
  • 3 in conversation