BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hadrien
Obsidian | Level 7

Hello, I am using SAS Enterprise Guide. I'd like to do some quick exploratory analysis of a data set that's already loaded in my work library, however when I run the code below I get the error message "Statement is not valid or is used out of proper order".

 

NROW(dataset);

I would also be very interested in learning what people's favorite EDA functions are, wish there was a SAS equivalent of the str() function in R.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Yeah. NROW(x) is IML code. if you are familiar with R ,then IML is every familiar with you . Here are two ways to know how much number of obs there are in a data frame/dataset/table :

 

/* 1) IML code: */
proc iml;
 use sashelp.class nobs nobs;
 read all var{age} into x;
 close;

 print nobs;
 print (nrow(x));
quit;

/* 2) Data Step: */

data _null_;
 set sashelp.class nobs=nobs;
 put nobs=;
 stop;
run;

/* 
  proc contents can also give you 
  all the information about that data frame / table . 
*/

proc contents data=sashelp.class varnum;
run;

 

 

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Errm, NROW() is a SAS IML function, needs to be in an IML statement.  There are many ways to find out number of observations, you could open the dataset and look, inspect its properties, do a data set statement and look at the log, proc sql count(*), proc means, proc freq, proc tabulate etc.

For EDA - see above procedures.  The R str() function returns attributes on the data yes?  If so then proc contents does the same, or look at the vcolumn/table in sashelp.library.

 

To add, do you know SAS at all?  You will need to learn the language and way of working to be able to pretty much anything, much like any programming language.

Hadrien
Obsidian | Level 7

My IT dept just confirmed we don't have a license for IML, which is why it wasn't working. Didn't realize there was different SAS functions for their different products.

Ksharp
Super User
proc contents can give you all the information about that data frame / table .


proc contents data=sashelp.class varnum;
run;
Ksharp
Super User

Yeah. NROW(x) is IML code. if you are familiar with R ,then IML is every familiar with you . Here are two ways to know how much number of obs there are in a data frame/dataset/table :

 

/* 1) IML code: */
proc iml;
 use sashelp.class nobs nobs;
 read all var{age} into x;
 close;

 print nobs;
 print (nrow(x));
quit;

/* 2) Data Step: */

data _null_;
 set sashelp.class nobs=nobs;
 put nobs=;
 stop;
run;

/* 
  proc contents can also give you 
  all the information about that data frame / table . 
*/

proc contents data=sashelp.class varnum;
run;

 

 

strmwzrd
Fluorite | Level 6

/* Here's a trick I occasionally use. Note only one record is read form each dataset but SAS magic knows all… */


Data my_dataset ;
   do I=1 to 27 ;
       output ;
   end ;
run ;

 

Data my_dataset2 ;
   do I=1 to 73 ;
      output ;
   end ;
run ;

 

data _null_ ;
    set my_dataset(obs=1) nobs=nobs ;
    call symputx('records',nobs) ;
run ;
%put records: &records ;

 

/* Here SAS knows how many obs are in the concatenated datasets too… */
data _null_ ;
    set my_dataset(obs=1) my_dataset2(obs=1) nobs=nobs ;
    call symputx('records',nobs) ;
run ;
%put Concatenated records: &records ;

 

The Log file:
NOTE: The data set WORK.MY_DATASET has 27 observations and 1 variables.


NOTE: The data set WORK.MY_DATASET2 has 73 observations and 1 variables.

NOTE: There were 1 observations read from the data set WORK.MY_DATASET.

 

records: 27

 

NOTE: There were 1 observations read from the data set WORK.MY_DATASET.
NOTE: There were 1 observations read from the data set WORK.MY_DATASET2.

Concatenated records: 100

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 72251 views
  • 2 likes
  • 4 in conversation