03-02-2017 08:28 PM
How do I create a new variable named 'Count' that starts at 1 on row 1 and increases by 1 increment through the last observation?
Is it possible to do this using proc sql? Or is it better to do it using the data stet?
03-02-2017 08:41 PM
There is already an automatic variable that does that. You just have to capture it in a data step. e.g.:
data want; set sashelp.class; count=_n_; run;
Art, CEO, AnalystFinder.com
03-03-2017 04:42 AM
The question would be why. It sounds like your coming from SQL to SAS and there is an understanding gap between the two. SQL does not assume sorted data - in fact apart from grouping and ordering, data can go in any way - hence why there are functions to create these types of ID field either automatically or by hand. In SAS however it is different, the basic functionality expects sorted data - i.e. by group processing (there is the unsorted option - however that doesn't mean the data is not sorted, just not logically). So as your data will always be in group by order for any processing, and id field should not be necessary, and if it is needed for some logic then you can just use _n_.
Need further help from the community? Please ask a new question.