abhishekdagarit
9/19/2017 - 3:34 PM

Creating/Importing data in SAS

Creating/Importing data in SAS

Creating/Importing a file in SAS


Creating a dataset inside SAS

There is a simple way to add some data inside data step.

It uses datalines

data d1;
input a b;
datalines;
1 2
2 3
4 5
2 2
5 76
4 2
;
run;```


```sas
proc print data = d1;
run;```


## Less variables, more data

When we have declared less variables but the input data is more. 


```sas
data work.test3;
input x y;
datalines;
1 2 55
3 2 112
5 3 223
3 1 4
5928 2 10
;
run;

proc print data = work.test3;
run;

Assignment is tricky when variables are more and values are less

data work.test4;
input x y p q;
datalines;
1 2 55
3 4 77
5 6 99
7 8 33
9    10 44
;
run;

proc print data = work.test4;
run;

This won't assign any value to x, y. Will leave it blank.

data test6;
input x y;
datalines;
1
;
run;
proc print data= test6;
run;

Rules for datalines

Datalines reads the data from one line and moves to the next line.

Linking a file in SAS

It uses infile

data work.test7;
infile 'e:\22jun\sp.txt';
input x y;
run;

Create data without datalines

data work.test8;
x=12;
y=123;
run;

proc print data = work.test8;
run;

Using inbuilt dataset

proc print data=sashelp.baseball;
run;

Type it slowly and it will show the list of all possible areas where you need to make this change.