BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
malakaext
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

7 REPLIES 7
art297
Opal | Level 21

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;

malakaext
Calcite | Level 5

Thank you very much!!! It worked.

malakaext
Calcite | Level 5

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

Linlin
Lapis Lazuli | Level 10

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;

malakaext
Calcite | Level 5

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.

Linlin
Lapis Lazuli | Level 10

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.

malakaext
Calcite | Level 5

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!!!!

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!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

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