Community talk about communities.sas.com. Meta!

SAS-novice questions: in which community to post?

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

SAS-novice questions: in which community to post?

Hi all,

 

I am a SAS-novice, and working through the book of Andy Field and Jeremy Miles "Discovering statistics using SAS".

I am encountering all kind of smaller hiccups doing the exercises in the book, what has to do with the SAS-program (and not with the statistics itself).

 

What is the proper platform/community for my questions. I will give one example.

 

One of the datafiles to be used for the exercises misses for some unknown reason a vairiable ID. I now want to create a variable (vector) ID with 50 records from 1 to 50, and to add that to the datafile. Of course I can add the data manually, but I want to learn to write some simple code. In R this is no problem for me. But is SAS I ran into troubles.

 

I created a vector V as follows:

 

PROC IML;

V=T(1:50);

 

Then aI tried to add that to the dataset

 

DATA set2; SET set1;

ID=V;

RUN;

 

Then in set2 two new empty variables have been created ID and V.

 

Thanks for the help.

 

Wil Tamis

 

 


Accepted Solutions
Solution
‎01-17-2016 04:27 PM
Super User
Posts: 17,912

Re: SAS-novice questions: in which community to post?

_n_ is an automatic variable, that iterates at the end of each data step iteration. 

 

It's not a row counter, but can be used as a row counter unless you're doing some complex data steps. 

 

It sounds like you have Base SAS, not EG (point and click interface) or SAS Studio (accessed via web browswer).

 

https://communities.sas.com/t5/forums/replypage/board-id/community_discussion/message-id/1323

 

If you're new to SAS, the SAS Analytics U page has training resources, free and paid, on the link on the right hand side. The first SAS programming e-course is free. 

 

 

View solution in original post


All Replies
Super User
Posts: 17,912

Re: SAS-novice questions: in which community to post?

Most of your questions can be posted under SAS Programming >Base SAS Programming.

 

 

Proc IML is not part of Base SAS. You can mix and go between data steps and Proc IML, but if you're new it might not be the best idea.

 

IML treats data like R, arrays/matrices and column functions. Base SAS does not, it goes through data line by line. 

 

That being said, if you want to add a row identifier of 1 to 50 to your data set you can use the automatic variable _n_. I'm not sure what you're trying to do with the 1 to 50 so this may or may not make sense. A great way to ask questions is to show the current structure/sample of your data and your desired output. 

 

DATA set2; 
SET set1;
ID=_n_;
RUN;
New Contributor
Posts: 2

Re: SAS-novice questions: in which community to post?

Thanks for the answer (it works) and the tips.

 

So, I have SAS 9.3, apparently dat is Base SAS?

 

Still have to find out why your solution works (_n_).

Solution
‎01-17-2016 04:27 PM
Super User
Posts: 17,912

Re: SAS-novice questions: in which community to post?

_n_ is an automatic variable, that iterates at the end of each data step iteration. 

 

It's not a row counter, but can be used as a row counter unless you're doing some complex data steps. 

 

It sounds like you have Base SAS, not EG (point and click interface) or SAS Studio (accessed via web browswer).

 

https://communities.sas.com/t5/forums/replypage/board-id/community_discussion/message-id/1323

 

If you're new to SAS, the SAS Analytics U page has training resources, free and paid, on the link on the right hand side. The first SAS programming e-course is free. 

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 507 views
  • 2 likes
  • 2 in conversation