Learning SAS? Welcome to the exclusive online community for all SAS learners.

How to use data after importing into SAS University?

Reply
Occasional Contributor
Posts: 6

How to use data after importing into SAS University?

So I have imported my data using the following:

 

PROC IMPORT DATAFILE="/folders/myfolders/uiversityProper.csv"
OUT=WORK.MYCSV
DBMS=CSV
REPLACE;
RUN;

 

I get a very nifty little layout of my variables and data under a tab called "OUTPUT DATA."

 

The thing is I have no idea what to do now. In class we were only taught how to manually create vectors of data as;

Y = {1,2,3,4,5,6,...}

 

I need to be able to concatenate and multiply, take inverses, etc. of my vectors and matrices.

 

How do I utilize my newly imported data? I apologize in advance if this seems like a simple question. I'm doing my best I promise! Smiley Happy

Thank you in advance.

Regular Contributor
Regular Contributor
Posts: 185

Re: How to use data after importing into SAS University?

Look in your Explorer window,

 

You should see Libraries and in there a folder called Work.  Your data set is likely in there.

 

I have no idea how to take the inverse of a matrix.

 

Start with

 

proc freq data= mycsv;
run;

 

or something.  Good luck. 

Occasional Contributor
Posts: 6

Re: How to use data after importing into SAS University?

I see it but I still don't know how to utilize it.

 

I even tried;

 

print VAR1;

 

Where VAR1 is one of my variables (a vector) but get this error;

 

"

ERROR: Matrix Acceptance_rate has not been set to a value.
 
statement : PRINT at line 63 column 1
"
 
So somehow I need to import the data into the code I'm writing because it's not recognizing these variables.
 
And I know how to perform the matrix operations that I need. I just need to get my variables to be usable :/

 

Regular Contributor
Regular Contributor
Posts: 185

Re: How to use data after importing into SAS University?

I would think if you are getting that error you are doing something.

 

We could speculate about your programming in general if you would like, but if you posted some actual code the experts here would likely be able to help you. 

Occasional Contributor
Posts: 6

Re: How to use data after importing into SAS University?

"PROC IMPORT DATAFILE="/folders/myfolders/uiversityProper.csv"
OUT=WORK.MYCSV
DBMS=CSV
REPLACE;
RUN;"

But I'm not having a problem getting the data in. The data reads in successfully and I can look at it. I just don't know how to work with the data.

For example, in R I would write something like;
mydata <- read.csv("C:\\DATA.csv")
VAR1 = mydata[,1]
VAR2 = mydata[,2]

etc.

After that I can utilize VAR 1 and VAR2 freely. I can multiply the vectors, invert the matrix product, etc.

Simply Put:

I need to get from an excel spreadsheet with a bunch of data to being able to manipulate the data in SAS.
Trusted Advisor
Posts: 1,613

Re: How to use data after importing into SAS University?

[ Edited ]

Just to give you some feeling and approach to your data:

 

In your code there is statement: OUT=WORK.MYCSV

On the left side of SAS STUDIO you will find the line: Libraries.

When you parse it you will find the library named work.

In it will be your sas dataset: mycsv.

Double click on the dataset name and see its details: lines are observation, columns are the variables.

First line contains the variable names of each column.

 

Now go back to code tab and type the next code:

proc print data=work.mycsv;
run;

check what did you got in the results tab.

 

Type next lines, in same program or as a new program:

proc contents data=work.mycsv;
run;

again, check results tab.

 

Lat's say you have in the dataset the variables: var1 var2 - both numeric.

Run next code and check output tab:

data my_sum;
set work.csv; new_var = var1 + var2; run;

You will need to learn more procedures to use, more functions to use - untill you'll be able to do what you want.

 

 

Occasional Contributor
Posts: 6

Re: How to use data after importing into SAS University?

[ Edited ]
ERROR: File WORK.CSV.DATA does not exist.
63 new_var = Tier_number + Freshman_retention;
64 run;
 
Additionally,
 
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.MY_SUM may be incomplete. When this step was stopped there were 0 observations and 3 variables.
WARNING: Data set WORK.MY_SUM was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
 
______________________________
 
I know what I want to do with this. It's just that I've only been taught how to manually enter data in. I want to be able to utilize SAS to do this since it's impossible to do manually with large datasets.
Trusted Advisor
Posts: 1,613

Re: How to use data after importing into SAS University?

Have you run your code:

PROC IMPORT DATAFILE="/folders/myfolders/uiversityProper.csv"
OUT=WORK.MYCSV
DBMS=CSV
REPLACE;
RUN;

did it run successfully ? 

You got error message: ERROR: File WORK.CSV.DATA does not exist. - which means it did not run or you got other errors.

Have you checked the log ?

 

The others steps failed because the dataset does not exist.

 

BTW - I have no experience with R language and don't know if it is possible or how to use it

with SAS University edition.

 

Trusted Advisor
Posts: 1,613

Re: How to use data after importing into SAS University?

[ Edited ]

You created work.mycsv dataset but tried run with work.csv which does not exist !

Occasional Contributor
Posts: 6

Re: How to use data after importing into SAS University?

Yes I figured that one out. Oops! :/

 

And I was able to define the newVar as you had in your code but I'm still having issues.

 

So I have a question:

 

What is the difference between the data SAS has (directly imported from Excel) and simply inputting manually as such;

y = {1,2,3,4,...}

 

When I do it manually I can easily do what I need to do e.g.:

 

proc iml;

Y = VAR1 || VAR2;

X = VAR 3 || VAR4;

H = X*inv(X`X) * X`

 

But when I do this I still cannot use the variables.. The newvar was created but I don't need to create variables for the dataset. I need to create my data matrix (for independent and dependent observations).

 

After that I know the code. But I can't seem to utilize SAS to get there.

 

"

proc iml;

Y = Graduation_rate || Freshman_retention;
ERROR: (execution) Matrix has not been set to a value.
 
operation : || at line 143 column 21
operands : Graduation_rate, Freshman_retention
 
Graduation_rate 0 row 0 col (type ?, size 0)
 
 
Freshman_retention 0 row 0 col (type ?, size 0)
"
 
But your code works. It's just that I still can't use matrix operations.

 

Occasional Contributor
Posts: 6

Re: How to use data after importing into SAS University?

Maybe I wasn't clear 100%.

 

How would I do the following types of operations,

 

proc iml;
outOfStateTuition = {3700,39849,40500,17704,40732,40569,42098,41958,
45290,42996,42786,41983,35551,41541,41992,42230,42280,41164,41417};

Y = outOfStateTuition * outOfStateTuition`;
print Y;

 

But without having to manually input the values for outOfStateTuition,

 

 

Trusted Advisor
Posts: 1,613

Re: How to use data after importing into SAS University?

Please look at proc iml documentation, given in next link:

https://support.sas.com/documentation/cdl/en/imlug/66845/HTML/default/viewer.htm#imlug_langref_sect0...

 

specifically at: 

Trusted Advisor
Posts: 1,613

Re: How to use data after importing into SAS University?

Sorry I have expertized witt SAS BASE and i'm not familiar with proc IML.

 

In many procedures you need define your input data, like in:

     proc prinnt data=<input> ...

     proc sort data=<input> out=<output> ...

     proc means data=<input> ...

Doesn't proc IML have its syntax to define the input dataset to work with ?

 

Everey sas dataset has its metadata with it, so that procedures and data steps recognize the variables and

their attributes.

 

When you write y = {1,2,3,4,...} you define an array of literal values.

In similar way you can define - in sas base data step sytax:

     

data want;
        set have;
            array y var1 var2 var3 var4;   /* assigning list of variables to array named Y */
            array yn  var1-var4;    /* assigning all variables in the range var1 to var4, same as above */
            /* then you can do a loop over all array members */
           do i=1 to dim(y);   /* or dim(yn) */
                x= y(i);
               put i= x=;  /* print to log */
          end;
    run;
             
Ask a Question
Discussion stats
  • 12 replies
  • 269 views
  • 0 likes
  • 3 in conversation