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

Hi, I am trying to assign a value to a proc iml input from my datatset.

 

proc iml;
NumWalks = 100;
NumSteps = 52;
Mean = 0.003;
SD = 0.03;

 

I want to assign mean and std from dataset of another table

 

STOCKNAME     MEAN     STD

A                          0.003     0.034

B                          0.006     0.05

 

How can I pull the mean and std value from the other dataset?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input STOCKNAME $ MEAN STD;
cards;
A 0.003 0.034
B 0.006 0.05
;


proc iml;
use have ;
read all var{STOCKNAME MEAN STD} ;
close;

NumWalks = 100;
NumSteps = 52;
Mean = MEAN[1];
SD = STD[1];

x = j(NumSteps, NumWalks);
call randseed(1234);
call randgen(x, "Normal", Mean, SD);

y = j(NumSteps, NumWalks);

z = x + y;

do i = 1 to NumWalks;
z[,i] = cuprod(z[,i]);
end;
create t1 from z[colname='COL']; append from z;
quit;

View solution in original post

5 REPLIES 5
Ksharp
Super User
Hard to understand what you are trying to do ?

data have;
input STOCKNAME $ MEAN STD;
cards;
A 0.003 0.034
B 0.006 0.05
;

proc iml;
use have ;
read all var{STOCKNAME MEAN STD} ;
close;
Mean = MEAN[1];
SD = STD[1];

print mean sd;
quit;
shubhodasgupta
Fluorite | Level 6

Thank you. I am trying to create a table where the mean and SD will vary as per the input table.

 

proc iml;
NumWalks = 100;
NumSteps = 52;
Mean = 0.003 (want to pull this value from have for next steps);
SD = 0.03 (want to pull this value from have for next steps);

x = j(NumSteps, NumWalks);
call randseed(1234);
call randgen(x, "Normal", Mean, SD);

y = j(NumSteps, NumWalks);

z = x + y;

do i = 1 to NumWalks;
z[,i] = cuprod(z[,i]);
end;
create t1 from z[colname='COL']; append from z;
quit;

data t2;
WEEK = _N_;
set t1;
run;

Ksharp
Super User
data have;
input STOCKNAME $ MEAN STD;
cards;
A 0.003 0.034
B 0.006 0.05
;


proc iml;
use have ;
read all var{STOCKNAME MEAN STD} ;
close;

NumWalks = 100;
NumSteps = 52;
Mean = MEAN[1];
SD = STD[1];

x = j(NumSteps, NumWalks);
call randseed(1234);
call randgen(x, "Normal", Mean, SD);

y = j(NumSteps, NumWalks);

z = x + y;

do i = 1 to NumWalks;
z[,i] = cuprod(z[,i]);
end;
create t1 from z[colname='COL']; append from z;
quit;
shubhodasgupta
Fluorite | Level 6

Thank you. Got my final result. 

PaigeMiller
Diamond | Level 26

Please explain further. Show us examples of the input table(s) and the desired output.

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 5 replies
  • 1201 views
  • 3 likes
  • 3 in conversation