BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Reeza
Super User

@Amanda_Lemon wrote:
Wait, why is it var5 that has a new value? I thought it should be that if the whole set (var 1 through var 5) is new, then increment the counter... no?

The BY has all 5 listed so it's grouped within those variables. Since var5 is the last it uniquely identifies your groups. 

Ie If Var2 stays the same it may still be a new group. 

 

BY group processing is incredibly powerful. It allows you to identify groups in your data for specific processing, so you can do the exact same thing for each BY group without loops. Run the following code as an example. You'll get a chart for each make. 

 

Proc sort data=SASHELP.cars out=cars;
By make;
Run;

Proc SGPLOT data=cars;
By make;
Scatter x=mpg_city y=mpg_highway;
Run;
Amanda_Lemon
Quartz | Level 8
One last question -- if I want the class variable to be saved in the excel file where the data set is instead of printing to display, how can I do that? Thank you in advance.
Rick_SAS
SAS Super FREQ

Do you have access to SAS/IML? Run

proc setinit; run;

and look in the SAS log.

Amanda_Lemon
Quartz | Level 8
I ran it and according to the log I have it.
Tom
Super User Tom
Super User

You have some good answers on how to create groups of records that the share same set of values.  

 

In terms of comparisons to other languages it is probably better to think of SAS in terms of relational databases.  Think of a SAS dataset not as a matrix but as a series of observations of a fixed number of variables.  In that case a two dimensional matrix is normally represented by three variables. One to store the actual value and one each for the row and column index.

 

I am still not sure what your data represents or even what calculation you are trying to do.  It kind of looks like your first column is the student id, but I am not sure what your 5 variables represent.  Are they the responses of 5 teachers?

data have ;
  input student @;
  do teacher=1 to 5 ;
    input rating @;
    output;
  end;
cards;
1	3	4	5	2	3
2	3	4	5	1	3
3	3	4	4	3	4
4	3	4	5	1	3
5	4	5	5	5	5
6	4	5	5	5	5
7	3	4	4	3	4
8	4	1	2	4	6
9	3	4	5	2	3
10	4	5	5	5	5
;

 Or perhaps they represent the 5 classes that the student had and the values are the ids of the teacher of the class?

data have ;
  input student @;
  do class=1 to 5 ;
    input teacher @;
    output;
  end;
cards;
1	3	4	5	2	3
2	3	4	5	1	3
3	3	4	4	3	4
4	3	4	5	1	3
5	4	5	5	5	5
6	4	5	5	5	5
7	3	4	4	3	4
8	4	1	2	4	6
9	3	4	5	2	3
10	4	5	5	5	5
;

 

Amanda_Lemon
Quartz | Level 8

As for my question about other languages, I guess to be more specific the question would be as follows: which programming language will allow me to convert a data set into a 2-dimensional array and then work easily with such an array? 

 

Thank you!

Reeza
Super User

@Amanda_Lemon wrote:

As for my question about other languages, I guess to be more specific the question would be as follows: which programming language will allow me to convert a data set into a 2-dimensional array and then work easily with such an array? 

 

Thank you!


Within SAS, IML will allow you to do that. But if you have character variables you'll also run into issues, because matrices/arrays are typically numeric. R dataframe will allow you to store mixed types.  Python and R are fairly similar when it comes to analysis. 

 

 

Amanda_Lemon
Quartz | Level 8
I haven't thought about IML... Thank you, Reeza!

Just to make sure I understand how it works -- do you mind showing how to convert a data set into a 2-dimensional matrix using IML?

Thanks again!
Rick_SAS
SAS Super FREQ

See the article "Reading ALL variables INTO a matrix."

Your example might look like:

 

proc iml;
use have;
read all var _NUM_ into X[colname=varNames];
close;

print X[colname=varNames];

To get started with SAS/IML, see "Ten tips for learning the SAS/IML language."

Amanda_Lemon
Quartz | Level 8
Thank you so much for the information!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 24 replies
  • 2132 views
  • 5 likes
  • 6 in conversation