Hello SAS Experts,
I'm coming from the R world and have some troubles getting started with SAS at the moment.
What I want to do:
I have a data set with names of cluster and now I want to simlulate lets say 50 random numbers for each cluster. I already found out to do it without using the data set of cluster names:
data A;
do ClusterID=1 to 100;
DO i=1 TO 50; ZV=Rannor(0);
output;
end;
end;
run;
But how do I do it now when I have the cluster names stored in a data set called clusterid with the variable name clustername?
Well, SAS is different than R, so although you'll probably get to where you're getting with this method, I'd suggest you explain a bit more of what you're trying to do and we can suggest the optimal SAS method to accomplish this. SAS works more on PROCEDURES and something like PROC SURVEYSELECT may be what you're looking for rather than manually doing randomly simulating data.
If you already had a data set another option is to use your data set as is. Let's say you had the SASHELP.CLASS data set and wanted to create 50 random variables for each person, it would loook like the following:
data want;
set sashelp.class;
do i=1 to 50;
zv = rannor(0);
output;
end;
run;
@mrer wrote:
Hello SAS Experts,
I'm coming from the R world and have some troubles getting started with SAS at the moment.
What I want to do:
I have a data set with names of cluster and now I want to simlulate lets say 50 random numbers for each cluster. I already found out to do it without using the data set of cluster names:
data A; do ClusterID=1 to 100; DO i=1 TO 50; ZV=Rannor(0); output; end; end; run;
But how do I do it now when I have the cluster names stored in a data set called clusterid with the variable name clustername?
Well, SAS is different than R, so although you'll probably get to where you're getting with this method, I'd suggest you explain a bit more of what you're trying to do and we can suggest the optimal SAS method to accomplish this. SAS works more on PROCEDURES and something like PROC SURVEYSELECT may be what you're looking for rather than manually doing randomly simulating data.
If you already had a data set another option is to use your data set as is. Let's say you had the SASHELP.CLASS data set and wanted to create 50 random variables for each person, it would loook like the following:
data want;
set sashelp.class;
do i=1 to 50;
zv = rannor(0);
output;
end;
run;
@mrer wrote:
Hello SAS Experts,
I'm coming from the R world and have some troubles getting started with SAS at the moment.
What I want to do:
I have a data set with names of cluster and now I want to simlulate lets say 50 random numbers for each cluster. I already found out to do it without using the data set of cluster names:
data A; do ClusterID=1 to 100; DO i=1 TO 50; ZV=Rannor(0); output; end; end; run;
But how do I do it now when I have the cluster names stored in a data set called clusterid with the variable name clustername?
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.
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.