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