LesezeichenAbonnierenRSS-Feed abonnieren
Community_Help
SAS Employee

allo zusammen,

ich möchte ein Makro für jeden einzelnen Tag eines Jahres programmieren. Gibt es hier eine Möglichkeit, eine DO-Schleife für jeden Tag zu erzeugen OHNE mit datepart zu arbeiten?
Mit datepart wäre die Umsetzung ziemlich einfach - einfach do i=19359 to 19723. Wenn ich datepart in meinem nächsten SQL-Schritt nutze, dann funktioniert dieser allerdings leider nicht.
Mein Datum liegt in folgendem Format vor: '01jan2013:00:00:00'dt.
Hoffe, jemand von euch kann mir helfen - auch ohne dass ich ein reproduzierbares Beispiel schreibe.

proc sql;

create table neu as

select tab1.name, datum

from db.tabelle tab1

where datum = '01jan2013:00:00:00'dt;

quit;

<code>

1 ANTWORT 1
LainieH
Community Manager

Hallo SAS-Anfängerin,

die Funktion intnx liefert das nächste Intervall. Wenn Du als immer genau auf ...:00:00 prüfen musst wäre die Logik so:

%macro jedenTag(year);

  %local NDays i ThisDt ThisD;

  Data _NULL_;

   call symputx("ndays",intck("DAY", "01JAN&YEAR."d,"31DEC&YEAR."d) + 1 );

  run;

  %put Das Jahr &Year. hat &nDays. Tage;

  %let ThisDT = %sysfunc(Intnx(DTDAY,"01JAN&YEAR.:00:00"dt,0,same));

  %do i = 1 %to &NDays.;

   %let ThisD = %sysfunc(putN(&ThisDT.,DTDate9.));

   proc sql;

  create table neu_&ThisD. as

  select tab1.name, datum

  from db.tabelle tab1

  where datum = &ThisDT.;

   quit

   /* weiterer Code */

   %let ThisDT = %sysfunc(Intnx(DTDAY,&ThisDT.,1,same));

  %end;

%mend;

%jedenTag(2013);

Falls Du aber auch Zeiten abweichend von :00:00 hast und haben willst, würde ich folgenden Code nehmen:


%macro jedenTag(year);

  %local NDays i ThisD;

  Data _NULL_;

   call symputx("ndays",intck("DAY", "01JAN&YEAR."d,"31DEC&YEAR."d) + 1 );

  run;

  %put Das Jahr &Year. hat &nDays. Tage;

  %let ThisD = %sysfunc(Intnx(DAY,"01JAN&YEAR."d,0,same));

  %do i = 1 %to &NDays.;

   proc sql;

  create table neu_&ThisD. as

  select tab1.name, datum

  from db.tabelle tab1

  where datepart(datum) = &ThisD.;

   quit

   /* weiterer Code */

   %let ThisD = %eval(&ThisD. + 1);

  %end;

%mend;

%jedenTag(2013);

Viele Grüße

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!

Diskussionsstatistiken
  • 1 Antwort
  • 1302 Aufrufe
  • 0 Kudos
  • 2 in Unterhaltung