DATA Step, Macro, Functions and more

Looping through a data set with cluster names and generate observations for each name

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Looping through a data set with cluster names and generate observations for each name

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?

 


Accepted Solutions
Solution
‎08-27-2017 03:09 PM
Super User
Posts: 19,855

Re: Looping through a data set with cluster names and generate observations for each name

[ Edited ]

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


All Replies
Solution
‎08-27-2017 03:09 PM
Super User
Posts: 19,855

Re: Looping through a data set with cluster names and generate observations for each name

[ Edited ]

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?

 



 

Occasional Contributor
Posts: 8

Re: Looping through a data set with cluster names and generate observations for each name

that was an easy solution to my problem! Thank you very much!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 181 views
  • 1 like
  • 2 in conversation