Can you provide some sample of your data? Makes it easier to provide usable code
It's always best if you can supply date both before and after the transformation you require, and details of what business logic gets you from one to the other. Assuming that you either ant 6 rows or 6 columns for each Terminal Installation, then this code should give you a solution that you can tune to meet your requirements
data sample ;
infile datalines truncover ;
input firstInstall date9. ;
format firstInstall date9. ;
datalines ;
05May2020
31Jul2020
; run ;
data long_Results ;
set sample ;
do i = 1 to 6 ;
month = intnx('month',firstinstall,i-1) ;
output ;
end ;
format month date9. ;
drop i ;
run ;
data wide_Results ;
set sample ;
array months[6] ;
do i = 1 to dim(months) ;
months[i] = intnx('month',firstinstall,i-1) ;
end ;
format months1-months6 date9. ;
drop i ;
run ;
I'm not sure what you mean - please could you give examples of the input table(s), and expected output table(s) results
I fear we still do not have a good clue about your data structure and contents.
Please supply data. Don't talk about it, don't try to describe it, show it.
Use a data step with datalines (or any other means, like loops) that creates a dataset we can use for developing and testing, like Novinosrin showed you here.
Then show the expected output from that particular dataset.
If your data really looks like that ("dates" as strings, wide layout), you suffer from useless data in a useless structure.
See this short example for intelligent data making the code simple:
data table1;
input id monthcount mnth :yymmn6.;
format date yymmd7.;
datalines;
1 1 202004
1 2 202005
1 3 202006
1 4 202007
1 5 202008
1 6 202009
;
data m1;
input id mnth :yymmn6. volume;
format mnth yymmd7.;
datalines;
1 202004 12
;
data m3;
input id mnth :yymmn6. volume;
format mnth yymmd7.;
datalines;
1 202005 15
;
data all / view=all;
set m:;
run;
data want;
merge
table1
all
;
by id mnth;
run;
proc report data=want;
column id mnth,volume;
define id / group;
define mnth / "Volume" across;
define volume / "" analysis sum;
run;
To show you how to make intelligent data out of what you have, supply it in DATA STEPS WITH DATALINES, as I'm not into the guessing game.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.