Forecasting using SAS Forecast Server, SAS/ETS, and more

array

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 91
Accepted Solution

array

hi,

Can someone please let me know how to take the y values generated by the following code to an array. the way i have written it produces only one line. i need all 2000 data preferably in an excel sheet.

(Im generating a garch(1,1) data set here ,; if u can check its validity that'll be greatly appreciated)

data sim;

sig=1;

    do i=1 to 2000;

    z=rannor(12346);

    y=sig*z;

    sig2= 1+ 0.3*y*y+0.4*sig*sig;

    sig=sqrt(sig2);

    end;

run;

proc print data=sim;

run;

Thanks

malaka.


Accepted Solutions
Solution
‎10-05-2012 06:34 PM
PROC Star
Posts: 7,360

Re: array

Malaka,

I'll have to leave the validity question for someone more qualified than me.  However, you don't need an array to get what you want, just an output statement.  e.g.:

data sim;

sig=1;

    do i=1 to 2000;

    z=rannor(12346);

    y=sig*z;

    sig2= 1+ 0.3*y*y+0.4*sig*sig;

    sig=sqrt(sig2);

OUTPUT;

    end;

run;

View solution in original post


All Replies
Solution
‎10-05-2012 06:34 PM
PROC Star
Posts: 7,360

Re: array

Malaka,

I'll have to leave the validity question for someone more qualified than me.  However, you don't need an array to get what you want, just an output statement.  e.g.:

data sim;

sig=1;

    do i=1 to 2000;

    z=rannor(12346);

    y=sig*z;

    sig2= 1+ 0.3*y*y+0.4*sig*sig;

    sig=sqrt(sig2);

OUTPUT;

    end;

run;

Frequent Contributor
Posts: 91

Re: array

Thank you very much!!! It worked.

Frequent Contributor
Posts: 91

Re: array

I there a way to write there data to an excel file?

Super Contributor
Posts: 1,636

Re: array

try:

libname ttt "c:\temp\create an excel file.xls";

proc sql; drop table ttt.sim; quit;

data ttt.sim;

sig=1;

    do i=1 to 2000;

    z=rannor(12346);

    y=sig*z;

    sig2= 1+ 0.3*y*y+0.4*sig*sig;

    sig=sqrt(sig2);

OUTPUT;

    end;

run;

libname ttt clear;

Frequent Contributor
Posts: 91

Re: array

Thanks. But it gives the following errors:

  libname ttt "F:\temp\create an excel file.xls";

ERROR: Connect: 'F:\temp\create an excel file.xls' is not a valid path.  Make

       sure that the path name is spelled correctly and that you are

       connected to the server on which the file resides.

ERROR: Error in the LIBNAME statement.

1549

1550  proc sql;

1551  drop table ttt.sim;

ERROR: Libname TTT is not assigned.

WARNING: Table TTT.sim has not been dropped.

1552  quit;

NOTE: The SAS System stopped processing this step because of errors.

NOTE: PROCEDURE SQL used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

1553

1554  data ttt.sim;

1555

1556

1557

1558  sig=1;

1559

1560

1561

1562      do i=1 to 2000;

1563

1564      z=rannor(12346);

1565

1566      y=sig*z;

1567

1568      sig2= 1+ 0.3*y*y+0.4*sig*sig;

1569

1570      sig=sqrt(sig2);

1571

1572  OUTPUT;

1573

1574      end;

1575

1576  run;

ERROR: Libname TTT is not assigned.

NOTE: The SAS System stopped processing this step because of errors.

NOTE: DATA statement used (Total process time):

      real time           0.03 seconds

      cpu time            0.01 seconds

1577

1578  libname ttt clear;

WARNING: Libname TTT is not assigned.

Super Contributor
Posts: 1,636

Re: array

It works on my computer. I have SAS 9.3 and SAS ACCESS. my log file:

210  libname ttt "c:\temp\create an excel file.xls";

NOTE: Libref TTT was successfully assigned as follows:

      Engine:        EXCEL

      Physical Name: c:\temp\create an excel file.xls

211  data ttt.sim;

212  sig=1;

213

214      do i=1 to 2000;

215      z=rannor(12346);

216      y=sig*z;

217      sig2= 1+ 0.3*y*y+0.4*sig*sig;

218      sig=sqrt(sig2);

219  OUTPUT;

220      end;

221  run;

NOTE: The data set TTT.sim has 2000 observations and 5 variables.

NOTE: DATA statement used (Total process time):

      real time           0.73 seconds

      cpu time            0.06 seconds

222  libname ttt clear;

NOTE: Libref TTT has been deassigned.

Frequent Contributor
Posts: 91

Re: array

Thank you very much! I have SAS 9.0. May be thats the reason.

However, I did it with the use of some papers I found online.

data sim;

sig=1;

    do i=1 to 2000;

    z=rannor(12346);

    y=sig*z;

    sig2= 1+ 0.3*y*y+0.4*sig*sig;

    sig=sqrt(sig2);

    output ;

end;

LIBNAME dat "c:\sas\data\";

PROC EXPORT DATA=sim

            OUTFILE="F:\data\sim.csv"

            DBMS=csv REPLACE;

RUN;

I appreciate every answer!!!!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 566 views
  • 6 likes
  • 3 in conversation