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

Tish is my other question.

I understand why u have to retain a=0.3. But I dont understand why you have to retain sig=1. Because you use sig=1 only for the first iteration. Starting from second sig value changes according to sig 2.

Can someone please explain it?

PGStats
Opal | Level 21

A datastep is an implicit do loop reading the input data. At each iterration all variables are set to missing, unless they are mentioned in a retain statement. The values mentioned in the retain statement are only initial values for the first iteration. The retained variables WILL NOT go back to their initial values at every iteration, rather, they will keep their values from the previous iteration.

Please answer Arthurs' question above. It must be the key to the problem.

PG

PG
malakaext
Calcite | Level 5

Thank you very much. That is a really  good explanation.

To Authur's question:

I checked it but I still think I used the same file. Anyway after writing the whole program again I started to get complete answers.

THANK YOU ALL FOR THE TREMENDOUS SUPPORT.. I REALLY APPRECIATE IT

Malaka.

Tom
Super User Tom
Super User

What does the number 1000 have to do with the problem?

If you have a dataset and you want to apply a formula to the values of the variables in it a normal data step will process all of the observations.

data sim;

  set test ;

  retain a 0.3 sig 1.0 ;

  z = rannor(123457);

  epsi = z*sig;

  sig2 = resq +  a*sig*sig;

  sig = sqrt(sig2);

run;

malakaext
Calcite | Level 5

I have attached the output file. Can you please tell me why it it incomplete.

Im new to SAS. Can you also tell me if your code changes the sig value in each step. Because I use sig=1 only for the first calculation. starting from the second epsi value it should use SQRT( sig2) which is affected by each resq value in the data set TEST.

Thanks

art297
Opal | Level 21

I would suggest running everything, from the import to exporting the output, and post your log here.  The log may show where the problem is.

malakaext
Calcite | Level 5

Here it is..

1869  data test;

1870  infile "F:\data\test.csv"  firstobs=2 DSD MISSOVER;

1871  input  return resq;

1872  run;

NOTE: The infile "F:\data\test.csv" is:

      File Name=F:\data\test.csv,

      RECFM=V,LRECL=256

NOTE: 1000 records were read from the infile "F:\data\test.csv".

      The minimum record length was 9.

      The maximum record length was 12.

NOTE: The data set WORK.TEST has 1000 observations and 2 variables.

NOTE: DATA statement used (Total process time):

      real time           0.02 seconds

      cpu time            0.01 seconds

1873

1874  data sim;

1875

1876    retain a 0.3 sig 1.0 ;

1877

1878    set test nobs=nobs ;

1879

1880    z = rannor(123457);

1881

1882    epsi = z*sig;

1883

1884    sig2 = resq +  a*sig*sig;

1885

1886    sig = sqrt(sig2);

1887

1888  run;

NOTE: Missing values were generated as a result of performing an operation on

      missing values.

      Each place is given by: (Number of times) at (Line):(Column).

      999 at 1882:11   1 at 1884:15     999 at 1884:19   1000 at 1886:9

NOTE: There were 1000 observations read from the data set WORK.TEST.

NOTE: The data set WORK.SIM has 1000 observations and 7 variables.

NOTE: DATA statement used (Total process time):

      real time           0.05 seconds

      cpu time            0.03 seconds

art297
Opal | Level 21

The file you are initially reading is not the one you originally posted.  When I read it my log shows:

      The minimum record length was 20.

      The maximum record length was 24.

Your log shows:

      The minimum record length was 9.

      The maximum record length was 12.

We both used the same code, thus I have to think we are not reading the same file.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 22 replies
  • 1639 views
  • 14 likes
  • 5 in conversation