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?
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.
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.