BookmarkSubscribeRSS Feed
srolash
Calcite | Level 5

Hi,

I wonder how we add a vector column with different values in the same data-step?

One solution is to create a document with the vector then merge it with the original document.

But, I'm interested to do it in the same document. Any help is extremely appreciable.

Thanks

3 REPLIES 3
PGStats
Opal | Level 21

Vectors and documents are not datastep concepts. As a rule, every variable created in a datastep becomes a variable (or column) in the dataset produced.

Please give an example (Input --> Output) of what you are trying to do.

PG

PG
srolash
Calcite | Level 5

Dear PGStats,

Thanks for your prompt reply.

Here's the example: to create a document for a planned study that contains:

- two schools, 50 boys and 50 girls from each school - total 200 pupils.

- for each group (e.g. school 1, 50 boys) to randomly assign a number and sort. The first 25 pupils get treatment and the next 25 pupils get control.

What I've done is as follows:

data a;

do school=1,2; do gender='F','M'; do id=1 to 50;

random=uniform(1);

output; end;end;end;

proc sort; by school gender random;

run;

data b; /*creating a vector of changing group values*/

do temp=1 to 4; do group='C','T'; do temp_1=1 to 25;

drop temp temp_1;

output; end;end;end;

run;

data all; merge a b;

run;

This works fine, but I was asked to do it in one document without merging an external document (I was given a tip of using count+1).

Do you have an idea how to resolve this?

Tremendous thanks

srolash
Calcite | Level 5

Dear PGStat,

Actually, I've just found out the answer has been posted elsewhere, so thanks for your help, really appreciate it.

With all my best,

srolash

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 831 views
  • 0 likes
  • 2 in conversation