Combining sample data into a single set

Reply
Occasional Contributor
Posts: 5

Combining sample data into a single set

Hi Guys,

 

Sorry for the beginner's question again.  We created the code below, and need to combine all the fc variables into a single output (column?) that we can sort and do procs on.  Thinking maybe array(?) but not sure about the syntax.  Any advice is welcome...we are super beginner SAS users so this may be very easy.  

Thanks!

 

 

data hw3prob3d;

seed=2345678;

lmu=10;

lsigma=2;

fmu=0;

fsigma=3;

fcmu=10;

do i=1 to 100000;

fx1=fmu+fsigma*rannor(seed);

fx2=fmu+fsigma*rannor(seed);

fx3=fmu+fsigma*rannor(seed);

fx4=fmu+fsigma*rannor(seed);

fx5=fmu+fsigma*rannor(seed);

lx1=lmu+lsigma*rannor(seed);

fc1=fx1+lx1;

fc2=fx2+lx1;

fc3=fx3+lx1;

fc4=fx4+lx1;

fc5=fx5+lx1;

n=5;

fcxbar=mean(fc1,fc2,fc3,fc4,fc5);

fcxstd=std(fc1,fc2,fc3,fc4,fc5);

    fcsxb=fcxstd/sqrt(n);

if abs(fcxbar-fcmu) > tinv(.975,n-1)*fcsxb then prob3c=1; else prob3c=0;

keep fcxbar fcxstd prob3c;

output;

end;

proc freq; table prob3c;

run;

Respected Advisor
Posts: 3,831

Re: Combining sample data into a single set

You could convert the numeric columns to strings and then concatenate these strings into a single column.

 

Alternatively most procedures can also deal with multiple columns. 

proc freq data=hw3prob3d;
  table fcxbar*fcxstd / list;
run;

proc sort data=hw3prob3d out=want;
  by fcxbar fcxstd;
run;

If you want separate tables then just use the BY statement within the Proc - or if the data is not sorted then a CLASS statement in Procs can often achieve the same outcome (but BY group processing is more efficient).

Respected Advisor
Posts: 4,606

Re: Combining sample data into a single set

Variable lists can be used in many contexts.

 

 

proc sort data=hw3prob3d;

by fc1-fc5;

run

 

proc glm data=hw3prob3d;

model fc1-fc5 = prob3c;

run;

PG
Occasional Contributor
Posts: 5

Re: Combining sample data into a single set

Thanks guys, these are helpful but not quite what I'm looking for, I think.

I should have been more clear...

 

What I want is for fc1-fc5 to be combined into a single column and under a new header (fc6).  Essentially I want to be able to find descriptive statistics for fc6 using proc univariate and the like.  

 

 

 

 

 

 

Grand Advisor
Posts: 10,210

Re: Combining sample data into a single set

It really helps to show a few rows of what you currently have and what you want that data to look like for that example.

Occasional Contributor
Posts: 5

Re: Combining sample data into a single set

Sure...keep in mind that the entire set of variables has 500,000 numbers in it (each variable fc1-fc5 has 100,000 random normal variables in the column).  

 

it basically looks like this now:

fc1      fc2     fc3    fc4    fc5

9         9        6       1       2

4         3        3       2       4

6         2        1       3       0

 

I want:

 

fc6

9

4

6

9

3

2

6

3

1

1

2

3

2

4

0

 

 

Occasional Contributor
Posts: 5

Re: Combining sample data into a single set

Sorry, I should add to the above that fc6 just represents all of the data in fc1-fc5 in a single column, it's not new data.

Respected Advisor
Posts: 3,831

Re: Combining sample data into a single set

Something like below?

data have;
  input fc1 fc2 fc3 fc4 fc5;
datalines;
9 9 6 1 2
4 3 3 2 4
6 2 1 3 0
;
run;

data want(keep=in_row source_var fc6);
  set have(keep=fc1-fc5);
  array fc {*} fc1-fc5;
  length in_row 8 source_var $3;
  in_row=_n_;
  do i=1 to dim(fc);
    source_var=vname(fc[i]);
    fc6=fc[i];
    output;
  end;
run;
Ask a Question
Discussion stats
  • 7 replies
  • 368 views
  • 0 likes
  • 4 in conversation