BookmarkSubscribeRSS Feed
makset
Obsidian | Level 7

At the beginning I will mention that I am just learning the hash table. I want to transpose a table and almost succeed. Here is my code:


data A;
informat datetime  datetime21.;
input datetime temperature pressure Nr ; 
format datetime  datetime21.;
cards;
01NOV2012:20:00:00	8.8386586448	1	112113
01NOV2012:20:01:00	9.7382110218	1	112113
01NOV2012:20:02:00	5.0758258603	1	112113
01NOV2012:20:03:00	8.8694050722	1	112113
01NOV2012:20:04:00	6.8936349358	1	112113
01NOV2012:20:05:00	9.432546082	1	112113
01NOV2012:20:06:00	9.2878638301	1	112113
01NOV2012:20:07:00	4.8766398407	1	112113
01NOV2012:20:08:00	7.7988508134	1	112113
01NOV2012:20:09:00	8.7713846681	1	112113
19DEC2013:00:00:00	3.1682274491	61	112113
19DEC2013:00:01:00	3.8016460347	61	112113
19DEC2013:00:02:00	0.0828465261	61	112113
19DEC2013:00:03:00	6.5064271912	61	112113
19DEC2013:00:04:00	7.5012415438	61	112113
19DEC2013:00:05:00	0.2482288703	61	112113
19DEC2013:00:06:00	8.2464989461	61	112113
19DEC2013:00:07:00	4.0366380266	61	112113
19DEC2013:00:08:00	4.2733701062	61	112113
19DEC2013:00:09:00	5.230450104	61	112113
29OCT2014:23:00:00	4.2798770685	121	112113
29OCT2014:23:01:00	7.3606959847	121	112113
29OCT2014:23:02:00	9.6644437662	121	112113
29OCT2014:23:03:00	0.4209582577	121	112113
29OCT2014:23:04:00	6.5941452747	121	112113
29OCT2014:23:05:00	0.6463373546	121	112113
29OCT2014:23:06:00	2.728187507	121	112113
29OCT2014:23:07:00	7.1689701942	121	112113
29OCT2014:23:08:00	3.5560273053	121	112113
29OCT2014:23:09:00	2.1887783287	121	112113
07DEC2017:23:00:00	0.4644698882	181	112113
07DEC2017:23:01:00	7.4807286961	181	112113
07DEC2017:23:02:00	5.35556752	181	112113
07DEC2017:23:03:00	9.3602973665	181	112113
07DEC2017:23:04:00	7.9723406397	181	112113
07DEC2017:23:05:00	1.3072503288	181	112113
07DEC2017:23:06:00	0.65210792	181	112113
07DEC2017:23:07:00	5.4844892211	181	112113
07DEC2017:23:08:00	7.0024573081	181	112113
07DEC2017:23:09:00	6.0352300038	181	112113
28JAN2004:23:00:00	3.4588757018	241	112114
28JAN2004:23:01:00	0.9221725771	241	112114
28JAN2004:23:02:00	8.3306752145	241	112114
28JAN2004:23:03:00	4.5803881995	241	112114
28JAN2004:23:04:00	8.2675979147	241	112114
28JAN2004:23:05:00	9.1477185837	241	112114
28JAN2004:23:06:00	5.7202544645	241	112114
28JAN2004:23:07:00	7.9451231612	241	112114
28JAN2004:23:08:00	0.9673189698	241	112114
28JAN2004:23:09:00	1.8442960829	241	112114
28MAR2006:23:00:00	6.3791716751	301	112114
28MAR2006:23:01:00	2.1213577455	301	112114
28MAR2006:23:02:00	7.9790208535	301	112114
28MAR2006:23:03:00	5.2773255971	301	112114
28MAR2006:23:04:00	8.6945169419	301	112114
28MAR2006:23:05:00	1.6644138051	301	112114
28MAR2006:23:06:00	0.0204887614	301	112114
28MAR2006:23:07:00	5.0024614809	301	112114
28MAR2006:23:08:00	5.4114883579	301	112114
28MAR2006:23:09:00	6.6648952151	301	112114
19OCT2011:00:00:00	6.7945698788	361	112114
19OCT2011:00:01:00	5.6084340392	361	112114
19OCT2011:00:02:00	9.3033694685	361	112114
19OCT2011:00:03:00	0.8323060418	361	112114
19OCT2011:00:04:00	6.897864067	361	112114
19OCT2011:00:05:00	6.0847914289	361	112114
19OCT2011:00:06:00	4.7261788161	361	112114
19OCT2011:00:07:00	4.3651668495	361	112114
19OCT2011:00:08:00	5.3854351002	361	112114
19OCT2011:00:09:00	9.6577573661	361	112114
16DEC2013:19:00:00	3.7592288386	421	112114
16DEC2013:19:01:00	5.5167134176	421	112114
16DEC2013:19:02:00	7.3533652583	421	112114
16DEC2013:19:03:00	5.7666407409	421	112114
16DEC2013:19:04:00	8.0186763406	421	112114
16DEC2013:19:05:00	5.0429561432	421	112114
16DEC2013:19:06:00	4.3662598124	421	112114
16DEC2013:19:07:00	8.0805433588	421	112114
16DEC2013:19:08:00	1.0869284347	421	112114
16DEC2013:19:09:00	3.2223363873	421	112114
23SEP2014:19:00:00	5.7138312096	481	112114
23SEP2014:19:01:00	9.8083063331	481	112114
23SEP2014:19:02:00	0.7149568223	481	112114
23SEP2014:19:03:00	6.3757409411	481	112114
23SEP2014:19:04:00	6.7465888965	481	112114
23SEP2014:19:05:00	1.9086576509	481	112114
23SEP2014:19:06:00	8.1664893031	481	112114
23SEP2014:19:07:00	3.7590556568	481	112114
23SEP2014:19:08:00	7.3485474777	481	112114
23SEP2014:19:09:00	9.9914430827	481	112114
11FEB2019:19:00:00	8.5294209281	541	112114
11FEB2019:19:01:00	1.6220973455	541	112114
11FEB2019:19:02:00	7.9244413553	541	112114
11FEB2019:19:03:00	9.1218567034	541	112114
11FEB2019:19:04:00	7.1427283529	541	112114
11FEB2019:19:05:00	4.5025826711	541	112114
11FEB2019:19:06:00	2.4023903767	541	112114
11FEB2019:19:07:00	9.7427219199	541	112114
11FEB2019:19:08:00	9.1612814669	541	112114
11FEB2019:19:09:00	6.319673683	541	112114
11MAR2008:17:00:00	7.3827899154	601	112115
11MAR2008:17:01:00	7.210859051	601	112115
11MAR2008:17:02:00	8.8476096536	601	112115
11MAR2008:17:03:00	4.682344154	601	112115
11MAR2008:17:04:00	9.9290248146	601	112115
11MAR2008:17:05:00	8.2291204389	601	112115
11MAR2008:17:06:00	8.0297554797	601	112115
11MAR2008:17:07:00	3.9942333312	601	112115
11MAR2008:17:08:00	9.6723125875	601	112115
11MAR2008:17:09:00	6.8582974235	601	112115
15MAY2009:20:00:00	0.6967037264	661	112115
15MAY2009:20:01:00	2.209698474	661	112115
15MAY2009:20:02:00	7.0656412118	661	112115
15MAY2009:20:03:00	3.4976043901	661	112115
15MAY2009:20:04:00	6.3166508637	661	112115
15MAY2009:20:05:00	4.1500182427	661	112115
15MAY2009:20:06:00	8.1335787382	661	112115
15MAY2009:20:07:00	0.5143562239	661	112115
15MAY2009:20:08:00	5.0487393979	661	112115
15MAY2009:20:09:00	3.2850281289	661	112115
10MAR2011:05:00:00	4.9747866485	721	112115
10MAR2011:05:01:00	7.05029523	721	112115
10MAR2011:05:02:00	1.1164530157	721	112115
10MAR2011:05:03:00	6.705195969	721	112115
10MAR2011:05:04:00	3.0150882155	721	112115
10MAR2011:05:05:00	3.6897646612	721	112115
10MAR2011:05:06:00	0.0299303746	721	112115
10MAR2011:05:07:00	1.6008544178	721	112115
10MAR2011:05:08:00	8.6340258014	721	112115
10MAR2011:05:09:00	9.5965762227	721	112115
06FEB2012:04:00:00	0.4850171693	781	112115
06FEB2012:04:01:00	3.0325717526	781	112115
06FEB2012:04:02:00	1.9730921229	781	112115
06FEB2012:04:03:00	9.1757692955	781	112115
06FEB2012:04:04:00	1.7643042444	781	112115
06FEB2012:04:05:00	2.2333751363	781	112115
06FEB2012:04:06:00	0.3155178041	781	112115
06FEB2012:04:07:00	5.5754801724	781	112115
06FEB2012:04:08:00	9.6805345081	781	112115
06FEB2012:04:09:00	0.4472889821	781	112115
27MAR2012:14:00:00	0.6278450065	841	112115
27MAR2012:14:01:00	4.8086930346	841	112115
27MAR2012:14:02:00	3.9867412089	841	112115
27MAR2012:14:03:00	4.087025465	841	112115
27MAR2012:14:04:00	4.2292779218	841	112115
27MAR2012:14:05:00	9.7946837055	841	112115
27MAR2012:14:06:00	9.5147549128	841	112115
27MAR2012:14:07:00	2.3544393363	841	112115
27MAR2012:14:08:00	6.5958845848	841	112115
27MAR2012:14:09:00	7.1473370702	841	112115
03MAR2015:21:00:00	3.0274132919	901	112115
03MAR2015:21:01:00	4.6789796697	901	112115
03MAR2015:21:02:00	3.2627761643	901	112115
03MAR2015:21:03:00	6.2627409864	901	112115
03MAR2015:21:04:00	9.4722208031	901	112115
03MAR2015:21:05:00	7.2383880219	901	112115
03MAR2015:21:06:00	8.4133591177	901	112115
03MAR2015:21:07:00	3.0224332935	901	112115
03MAR2015:21:08:00	2.2182885674	901	112115
03MAR2015:21:09:00	3.8854886894	901	112115
20JAN2016:13:00:00	8.8339482551	961	112115
20JAN2016:13:01:00	9.9984312756	961	112115
20JAN2016:13:02:00	3.6358541274	961	112115
20JAN2016:13:03:00	5.2535630809	961	112115
20JAN2016:13:04:00	3.2169948774	961	112115
20JAN2016:13:05:00	6.7585500027	961	112115
20JAN2016:13:06:00	0.8276014449	961	112115
20JAN2016:13:07:00	1.0962000792	961	112115
20JAN2016:13:08:00	3.3902002592	961	112115
20JAN2016:13:09:00	1.8370366748	961	112115
05AUG2016:22:00:00	8.216716242	1021	112115
05AUG2016:22:01:00	8.7472304446	1021	112115
05AUG2016:22:02:00	0.4472922022	1021	112115
05AUG2016:22:03:00	5.6399317854	1021	112115
05AUG2016:22:04:00	7.9897754826	1021	112115
05AUG2016:22:05:00	1.4684082754	1021	112115
05AUG2016:22:06:00	1.9898261293	1021	112115
05AUG2016:22:07:00	4.106047512	1021	112115
05AUG2016:22:08:00	8.7406910001	1021	112115
05AUG2016:22:09:00	2.638587181	1021	112115
01FEB2019:20:00:00	7.2510209843	1081	112115
01FEB2019:20:01:00	5.0215422432	1081	112115
01FEB2019:20:02:00	3.4856430744	1081	112115
01FEB2019:20:03:00	2.3379107565	1081	112115
01FEB2019:20:04:00	1.4276676858	1081	112115
01FEB2019:20:05:00	7.747606195	1081	112115
01FEB2019:20:06:00	5.0278010475	1081	112115
01FEB2019:20:07:00	9.1021693544	1081	112115
01FEB2019:20:08:00	9.8174049985	1081	112115
run;


data want2;
  do i = 1 to 10;
  if _N_ = 1 then do ;
declare hash H() ;
   H.defineKey ("datetime") ;
   H.defineData("datetime", "temperature","pressure","nr") ;
   H.defineDone() ;
end ;
set A;
array temperature_	temperature_1	-	temperature_10;
array pressure_	pressure_1 - pressure_10;
temperature_[i] = temperature;
pressure_[i] = pressure;
end ;
drop i temperature pressure;
run;

One thing i can't do, i want the datetime variable in the table wont always be in the first position ie if i = 1; (it's not enough to cut off 9 minutes, it's just an example)

Please check if everything is ok, maybe it can be done smarter and faster because I have ower 2GB of data.

thank you in advance for your help
3 REPLIES 3
Patrick
Opal | Level 21

The logic of your data want2 step looks incomplete and doesn't really align with the little bit you tell us. 

Please describe in more detail what you have and especially what you need. 

As a first impression: Not sure that using a hash table is the right thing to do here starting with: Do you have sufficient memory available in your session to load 2GB of data into a hash table?

ChrisNZ
Tourmaline | Level 20

What are you trying to achieve?

What does the expected output look like?

 

mkeintz
PROC Star

It appears that you have records in groups of 10.  Each group has a constant pressure unique to that group.  And each group also has a constant value for NR, although the NR can be shared with other groups.

 

So I presume you want to convert 10 records to 1 record, such that

  • The record has a single variable for pressure and nr
  • The record has ten datetime variables and ten temperature variables.

If the above is correct, then you have a simple data step program which reads in 10 records, placing datetime and temperature values into corresponding arrays of ten variables, followed by a single output, as in:

 

data A;
  informat datetime  datetime21.;
  input datetime temperature pressure Nr ; 
  format datetime  datetime21.;
cards;
01NOV2012:20:00:00	8.8386586448	1	112113
01NOV2012:20:01:00	9.7382110218	1	112113
01NOV2012:20:02:00	5.0758258603	1	112113
01NOV2012:20:03:00	8.8694050722	1	112113
01NOV2012:20:04:00	6.8936349358	1	112113
01NOV2012:20:05:00	9.432546082	1	112113
01NOV2012:20:06:00	9.2878638301	1	112113
01NOV2012:20:07:00	4.8766398407	1	112113
01NOV2012:20:08:00	7.7988508134	1	112113
01NOV2012:20:09:00	8.7713846681	1	112113
19DEC2013:00:00:00	3.1682274491	61	112113
19DEC2013:00:01:00	3.8016460347	61	112113
19DEC2013:00:02:00	0.0828465261	61	112113
19DEC2013:00:03:00	6.5064271912	61	112113
19DEC2013:00:04:00	7.5012415438	61	112113
19DEC2013:00:05:00	0.2482288703	61	112113
19DEC2013:00:06:00	8.2464989461	61	112113
19DEC2013:00:07:00	4.0366380266	61	112113
19DEC2013:00:08:00	4.2733701062	61	112113
19DEC2013:00:09:00	5.230450104	61	112113
29OCT2014:23:00:00	4.2798770685	121	112113
29OCT2014:23:01:00	7.3606959847	121	112113
29OCT2014:23:02:00	9.6644437662	121	112113
29OCT2014:23:03:00	0.4209582577	121	112113
29OCT2014:23:04:00	6.5941452747	121	112113
29OCT2014:23:05:00	0.6463373546	121	112113
29OCT2014:23:06:00	2.728187507	121	112113
29OCT2014:23:07:00	7.1689701942	121	112113
29OCT2014:23:08:00	3.5560273053	121	112113
29OCT2014:23:09:00	2.1887783287	121	112113
07DEC2017:23:00:00	0.4644698882	181	112113
07DEC2017:23:01:00	7.4807286961	181	112113
07DEC2017:23:02:00	5.35556752	181	112113
07DEC2017:23:03:00	9.3602973665	181	112113
07DEC2017:23:04:00	7.9723406397	181	112113
07DEC2017:23:05:00	1.3072503288	181	112113
07DEC2017:23:06:00	0.65210792	181	112113
07DEC2017:23:07:00	5.4844892211	181	112113
07DEC2017:23:08:00	7.0024573081	181	112113
07DEC2017:23:09:00	6.0352300038	181	112113
28JAN2004:23:00:00	3.4588757018	241	112114
28JAN2004:23:01:00	0.9221725771	241	112114
28JAN2004:23:02:00	8.3306752145	241	112114
28JAN2004:23:03:00	4.5803881995	241	112114
28JAN2004:23:04:00	8.2675979147	241	112114
28JAN2004:23:05:00	9.1477185837	241	112114
28JAN2004:23:06:00	5.7202544645	241	112114
28JAN2004:23:07:00	7.9451231612	241	112114
28JAN2004:23:08:00	0.9673189698	241	112114
28JAN2004:23:09:00	1.8442960829	241	112114
28MAR2006:23:00:00	6.3791716751	301	112114
28MAR2006:23:01:00	2.1213577455	301	112114
28MAR2006:23:02:00	7.9790208535	301	112114
28MAR2006:23:03:00	5.2773255971	301	112114
28MAR2006:23:04:00	8.6945169419	301	112114
28MAR2006:23:05:00	1.6644138051	301	112114
28MAR2006:23:06:00	0.0204887614	301	112114
28MAR2006:23:07:00	5.0024614809	301	112114
28MAR2006:23:08:00	5.4114883579	301	112114
28MAR2006:23:09:00	6.6648952151	301	112114
19OCT2011:00:00:00	6.7945698788	361	112114
19OCT2011:00:01:00	5.6084340392	361	112114
19OCT2011:00:02:00	9.3033694685	361	112114
19OCT2011:00:03:00	0.8323060418	361	112114
19OCT2011:00:04:00	6.897864067	361	112114
19OCT2011:00:05:00	6.0847914289	361	112114
19OCT2011:00:06:00	4.7261788161	361	112114
19OCT2011:00:07:00	4.3651668495	361	112114
19OCT2011:00:08:00	5.3854351002	361	112114
19OCT2011:00:09:00	9.6577573661	361	112114
16DEC2013:19:00:00	3.7592288386	421	112114
16DEC2013:19:01:00	5.5167134176	421	112114
16DEC2013:19:02:00	7.3533652583	421	112114
16DEC2013:19:03:00	5.7666407409	421	112114
16DEC2013:19:04:00	8.0186763406	421	112114
16DEC2013:19:05:00	5.0429561432	421	112114
16DEC2013:19:06:00	4.3662598124	421	112114
16DEC2013:19:07:00	8.0805433588	421	112114
16DEC2013:19:08:00	1.0869284347	421	112114
16DEC2013:19:09:00	3.2223363873	421	112114
23SEP2014:19:00:00	5.7138312096	481	112114
23SEP2014:19:01:00	9.8083063331	481	112114
23SEP2014:19:02:00	0.7149568223	481	112114
23SEP2014:19:03:00	6.3757409411	481	112114
23SEP2014:19:04:00	6.7465888965	481	112114
23SEP2014:19:05:00	1.9086576509	481	112114
23SEP2014:19:06:00	8.1664893031	481	112114
23SEP2014:19:07:00	3.7590556568	481	112114
23SEP2014:19:08:00	7.3485474777	481	112114
23SEP2014:19:09:00	9.9914430827	481	112114
11FEB2019:19:00:00	8.5294209281	541	112114
11FEB2019:19:01:00	1.6220973455	541	112114
11FEB2019:19:02:00	7.9244413553	541	112114
11FEB2019:19:03:00	9.1218567034	541	112114
11FEB2019:19:04:00	7.1427283529	541	112114
11FEB2019:19:05:00	4.5025826711	541	112114
11FEB2019:19:06:00	2.4023903767	541	112114
11FEB2019:19:07:00	9.7427219199	541	112114
11FEB2019:19:08:00	9.1612814669	541	112114
11FEB2019:19:09:00	6.319673683	541	112114
11MAR2008:17:00:00	7.3827899154	601	112115
11MAR2008:17:01:00	7.210859051	601	112115
11MAR2008:17:02:00	8.8476096536	601	112115
11MAR2008:17:03:00	4.682344154	601	112115
11MAR2008:17:04:00	9.9290248146	601	112115
11MAR2008:17:05:00	8.2291204389	601	112115
11MAR2008:17:06:00	8.0297554797	601	112115
11MAR2008:17:07:00	3.9942333312	601	112115
11MAR2008:17:08:00	9.6723125875	601	112115
11MAR2008:17:09:00	6.8582974235	601	112115
15MAY2009:20:00:00	0.6967037264	661	112115
15MAY2009:20:01:00	2.209698474	661	112115
15MAY2009:20:02:00	7.0656412118	661	112115
15MAY2009:20:03:00	3.4976043901	661	112115
15MAY2009:20:04:00	6.3166508637	661	112115
15MAY2009:20:05:00	4.1500182427	661	112115
15MAY2009:20:06:00	8.1335787382	661	112115
15MAY2009:20:07:00	0.5143562239	661	112115
15MAY2009:20:08:00	5.0487393979	661	112115
15MAY2009:20:09:00	3.2850281289	661	112115
10MAR2011:05:00:00	4.9747866485	721	112115
10MAR2011:05:01:00	7.05029523	721	112115
10MAR2011:05:02:00	1.1164530157	721	112115
10MAR2011:05:03:00	6.705195969	721	112115
10MAR2011:05:04:00	3.0150882155	721	112115
10MAR2011:05:05:00	3.6897646612	721	112115
10MAR2011:05:06:00	0.0299303746	721	112115
10MAR2011:05:07:00	1.6008544178	721	112115
10MAR2011:05:08:00	8.6340258014	721	112115
10MAR2011:05:09:00	9.5965762227	721	112115
06FEB2012:04:00:00	0.4850171693	781	112115
06FEB2012:04:01:00	3.0325717526	781	112115
06FEB2012:04:02:00	1.9730921229	781	112115
06FEB2012:04:03:00	9.1757692955	781	112115
06FEB2012:04:04:00	1.7643042444	781	112115
06FEB2012:04:05:00	2.2333751363	781	112115
06FEB2012:04:06:00	0.3155178041	781	112115
06FEB2012:04:07:00	5.5754801724	781	112115
06FEB2012:04:08:00	9.6805345081	781	112115
06FEB2012:04:09:00	0.4472889821	781	112115
27MAR2012:14:00:00	0.6278450065	841	112115
27MAR2012:14:01:00	4.8086930346	841	112115
27MAR2012:14:02:00	3.9867412089	841	112115
27MAR2012:14:03:00	4.087025465	841	112115
27MAR2012:14:04:00	4.2292779218	841	112115
27MAR2012:14:05:00	9.7946837055	841	112115
27MAR2012:14:06:00	9.5147549128	841	112115
27MAR2012:14:07:00	2.3544393363	841	112115
27MAR2012:14:08:00	6.5958845848	841	112115
27MAR2012:14:09:00	7.1473370702	841	112115
03MAR2015:21:00:00	3.0274132919	901	112115
03MAR2015:21:01:00	4.6789796697	901	112115
03MAR2015:21:02:00	3.2627761643	901	112115
03MAR2015:21:03:00	6.2627409864	901	112115
03MAR2015:21:04:00	9.4722208031	901	112115
03MAR2015:21:05:00	7.2383880219	901	112115
03MAR2015:21:06:00	8.4133591177	901	112115
03MAR2015:21:07:00	3.0224332935	901	112115
03MAR2015:21:08:00	2.2182885674	901	112115
03MAR2015:21:09:00	3.8854886894	901	112115
20JAN2016:13:00:00	8.8339482551	961	112115
20JAN2016:13:01:00	9.9984312756	961	112115
20JAN2016:13:02:00	3.6358541274	961	112115
20JAN2016:13:03:00	5.2535630809	961	112115
20JAN2016:13:04:00	3.2169948774	961	112115
20JAN2016:13:05:00	6.7585500027	961	112115
20JAN2016:13:06:00	0.8276014449	961	112115
20JAN2016:13:07:00	1.0962000792	961	112115
20JAN2016:13:08:00	3.3902002592	961	112115
20JAN2016:13:09:00	1.8370366748	961	112115
05AUG2016:22:00:00	8.216716242	1021	112115
05AUG2016:22:01:00	8.7472304446	1021	112115
05AUG2016:22:02:00	0.4472922022	1021	112115
05AUG2016:22:03:00	5.6399317854	1021	112115
05AUG2016:22:04:00	7.9897754826	1021	112115
05AUG2016:22:05:00	1.4684082754	1021	112115
05AUG2016:22:06:00	1.9898261293	1021	112115
05AUG2016:22:07:00	4.106047512	1021	112115
05AUG2016:22:08:00	8.7406910001	1021	112115
05AUG2016:22:09:00	2.638587181	1021	112115
01FEB2019:20:00:00	7.2510209843	1081	112115
01FEB2019:20:01:00	5.0215422432	1081	112115
01FEB2019:20:02:00	3.4856430744	1081	112115
01FEB2019:20:03:00	2.3379107565	1081	112115
01FEB2019:20:04:00	1.4276676858	1081	112115
01FEB2019:20:05:00	7.747606195	1081	112115
01FEB2019:20:06:00	5.0278010475	1081	112115
01FEB2019:20:07:00	9.1021693544	1081	112115
01FEB2019:20:08:00	9.8174049985	1081	112115
run;


data want;
  do i=1 to 10; 
    set a;
	array dt  {10} datetime1-datetime10;
	array tmp {10} temperature1-temperature10 ;
	dt{i}=datetime;
	tmp{i}=temperature;
  end;
  format datetime1-datetime10 datetime21. ;
  drop i datetime temperature;
run;

But you might not like the fact that this places all ten datetime variables in front of all ten temperature variables.  You might instead prefer to have 10 PAIRS of variables (i.e.  datetime1/temperature1,  datetime2/temperatue2, ....).  If so, then:

 

data want;
  do i=1 to 10; 
    set a;
	length datetime1 temperature1  datetime2 temperature2  datetime3 temperature3 
           datetime4 temperature4  datetime5 temperature5  datetime6 temperature6 
           datetime7 temperature7  datetime8 temperature8  datetime9 temperature9 
           datetime10 temperature1 8;
	array dt  {10} datetime1-datetime10;
	array tmp {10} temperature1-temperature10 ;
	dt{i}=datetime;
	tmp{i}=temperature;
  end;
  format datetime1-datetime10 datetime21. ;
  drop i datetime temperature;
run;

 

Oh, and thank you very much for provided the needed data in a data step form.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 521 views
  • 0 likes
  • 4 in conversation