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

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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?

 



 

View solution in original post

2 REPLIES 2
Reeza
Super User

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?

 



 

mrer
Fluorite | Level 6
that was an easy solution to my problem! Thank you very much!

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!

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
  • 2 replies
  • 797 views
  • 1 like
  • 2 in conversation