BookmarkSubscribeRSS Feed
Swapnil_21
Obsidian | Level 7

Hi, 

I have one dataset as below 

 

Account_id Account_name Credit_balance Debit_Balance

1 Ajay 100 200

2 Vijay 300 400

 

Now I need something like this in the same datastep

 

Data changed;

Set Input;

Credit_balance_changed= ranuni("uniform") *credit_balance;

* Here this value of Credit_balance and its randomly generated

variable I need in the same datastep*

Something like below 

Call execute (' proc sql; insert into new_table (select Credit_balance, 

Credit_balance_changed) 

 

But somehow I am not able to get the correct results. 

Any help is really appreciated 

 

 

3 REPLIES 3
ballardw
Super User

Is the value from the other data set supposed to brought into data set Changed?

Is there some rule for which value gets brought in? Such as matching on the Account_id or Account_name?

 

 

Call execute stacks code that executes after the data step that uses it. So there isn't any way you are going to get results into the data step creating changed.

 

It probably would be a good idea to actually show what that "other table" that you haven't even bothered to name contains.

Swapnil_21
Obsidian | Level 7
E. G.
Input
Account_id Account_name Credit_balance Debit_Balance

1 Ajay 100 200

2 Vijay 300 400

The other output table which I want is something like this. There is no structure as such. I just need to save the original value and its randomly changed value. So table would be something like below

Account_id Credit_balance Credit_balance_changed Debit_Balance Debit_balance_changed

1 100 312 200 516

2 300 678 400 794

So basically I need to store original value and its changed value somewhere so that it can be referred later
ballardw
Super User

So you want to create a random number. Do you have any rules for how to make such?

 

SAS has several functions that create random numbers and one, RAND that will create random numbers from many different distributions.

Example of just a few:

data example;
   do i=1 to 10;
      rn = rand('normal',0,1);
      rb = rand('binomial', .5,10);
      rbeta = rand('beta',4,12);
      rchi  = rand('chisquare',17);
      output;
   end;
run;

You would call one of these, or other functions, to create your random number in a data step.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 276 views
  • 0 likes
  • 2 in conversation