Data input through Do Loop

Today I had to enter a set of 64 Y variables in a 4*4*4 table with A, B and Block each having 4 levels, here is how I did it.

 

data split;
do A=1 to 4;
do B=1 to 4;
do Block= 1 to 4;
input Y;
output;
end;
end;
end;
cards;
42.9
41.6
28.9
30.8
53.8
58.5
43.9
46.3
49.5
53.8
40.7
39.4
44.4
41.8
28.3
34.7
53.3
69.6
45.4
35.1
57.6
69.6
42.4
51.9
59.8
65.8
41.4
45.4
64.1
57.4
44.1
51.6
62.3
58.5
44.6
50.3
63.4
50.4
45
46.7
64.5
46.1
62.6
50.3
63.6
56.1
52.7
51.8
75.4
65.6
54
52.7
70.3
67.3
57.6
58.5
68.8
65.3
45.6
51
71.6
69.4
56.6
47.4
;
run;

*showing only first five rows;

proc print data=oat1 (obs=5);
run;

Obs A B Block Y
1 1 1 1 42.9
2 1 1 2 41.6
3 1 1 3 28.9
4 1 1 4 30.8
5 1 2 1 53.8

Two steps: data and proc

There are basically two steps doing things in SAS. one is creating, manipulating data, The DATA step and another is all other functions including statistical, the PROC step.

I will cover both steps and many procedures later but here is quick look for how to use them.

Use DATA STEPS to:

    • Create and import data:

data data1;
input a b c;
cards;
1 2 3
4 5 6
7 8 9
;
run;

The result is the following table

Obs a b c
1 1 2 3
2 4 5 6
3 7 8 9

data data3;
infile 'D:/sas/data3.dat';
input a b c d;
run;

This will read data3.dat file into data3 which has four variables as given in input statement.

data

random1;

data random1;
do i = 1 to 10;
x = normal(0);
y = uniform(0);
output;
end;
run;

The result is the following table
Obs i x y
1 1 -1.52857 0.41513
2 2 0.08083 0.53118
3 3 1.98095 0.32572
4 4 -0.26286 0.38283
5 5 -0.01880 0.21665
6 6 -0.04803 0.43361
7 7 -1.46001 0.46454
8 8 1.19792 0.13875
9 9 -1.63991 0.31687
10 10 1.00099 0.07637

 

    • Modify and manipulate data:

data data2; set data1;
d=(a+b)/c;
loga=log10(a);
drop a;
run;

The result is the following table

Obs b c d loga
1 2 3 1.00000 0.00000
2 5 6 1.50000 0.60206
3 8 9 1.66667 0.84510

data

random2; set random1;

data random2; set random1;
if x<0 then out1='Neg';
else out1='Pos';
if y<.5 then out2='F';
else out1='P';
run;

The result is the following table
Obs i x y out1 out2
1 1 -1.52857 0.41513 Neg F
2 2 0.08083 0.53118 Pos P
3 3 1.98095 0.32572 Pos F
4 4 -0.26286 0.38283 Neg F
5 5 -0.01880 0.21665 Neg F
6 6 -0.04803 0.43361 Neg F
7 7 -1.46001 0.46454 Neg F
8 8 1.19792 0.13875 Pos F
9 9 -1.63991 0.31687 Neg F
10 10 1.00099 0.07637 Pos F

 

Use PROC STEPS to:

  • Sort data (PROC SORT)
  • Statistical summary (PROC MEANs, PROC UNIVARIATE)
  • Graphics (PROC PLOT, PROC GPLOT)
  • Many Statistical procedures (PROC GLM, PROC MIXED, PROC PRINCOMP, …)
  • Advanced data techniques (PROC SQL)
  • Matrix operations (PROC IML)
  • ……………and many more

I will discuss many topics later

What is SAS?

 

SAS is probably the most widely used commercial data analysis software. visit www.sas.com for more information.

lets look at the home screen of SAS

sashomescreen

 

This is the typical SAS screen where you have Results and Explorer sidebars and Log, output and editor windows. Html window is shown only if you activate html result in preferences setting. If you closed any of these windows, you can view them again from view menu.

Editor window: this is where you write codes to execute.

Log window: Name says itself, its log of what you do, what’s happening and any error , warning message.

Output: you get the output after running the code.

Results viewer: in HTML format (if activated)

all for today