turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Create a column that contains a count from 1 to th...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jun 17, 2013 4:49 AM
(7064 views)

Hi,

here is another question:

I sometimes want to create graphs where the x-axis is a count (as the row number), instead of column from the data table itself, for example time. Much like when doing a graph in Excel using the 'line' graph option. To do that I need an easy way to create a column which simple is the count or number of the row.

In Base SAS it would be:

data y;set x;nobs=_N_;run;

which adds nobs as a count of the observation number.

Thanks in advance

Poul

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jun 17, 2013 5:24 AM
(12457 views)

There are at least three quick ways to do this.

1. In a new empty column there is the option "initialize data" in the column dialog. Choose sequence, default should be a linear series in steps of 1.

2. A single-command column formula: *Row()*

3. Add two numbers (e.g. 1 and 2) in the first two rows of your counter column and right click and select the adequate *Fill* option, e.g *Continue sequence to end of table...*.

5 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jun 17, 2013 4:53 AM
(6468 views)

Hi.

In what other way would you like to create the nobs?

You say *in Base SAS it would be...so on;*

So, you need an alternative to what you have already provided as solution?

Thanks!

I see this is posted in JMP, ok, so have you tried the *COUNT* function?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jun 17, 2013 5:18 AM
(6468 views)

True, this was posted in JMP discussion, - I did not mention. However, I looked into the Count as you suggested, and fail to see, how it could be used as desired. What does count do, actually? It seems that would have to count to an upper value, which is the number of rows, but how to obtain that?

Sorry, for asking these simple questions here. After starting to use JMP I have to learn many things over. In Base SAS it was very simple.

Regards

Poul

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jun 17, 2013 5:24 AM
(12458 views)

There are at least three quick ways to do this.

1. In a new empty column there is the option "initialize data" in the column dialog. Choose sequence, default should be a linear series in steps of 1.

2. A single-command column formula: *Row()*

3. Add two numbers (e.g. 1 and 2) in the first two rows of your counter column and right click and select the adequate *Fill* option, e.g *Continue sequence to end of table...*.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jun 17, 2013 7:00 AM
(6468 views)

All of the recommended work. Thanks.

That makes me aks the next question:

I used to do like this in SAS code:

data mydata(drop=column_ID_1_old);

retain column_ID_1;

column_ID_1_old=column_ID_1;

set mydata;

if nobs=. then nobs=1;

else if (column_ID_1=column_ID_1_old) then nobs=nobs+1;else nobs=1;

run;

column_ID_1 would have a categorical value of some kind, based upon which the numbering would restart, each time the column_ID_1 changed its value. This is very useful when creating graphs that have panes that wrap. All of these must have the same x-axes, otherwise the graphs do not line up nicely. At least so I found.

So, my next question is: How to do this in JMP? Create the new column so that it restarts counting when another columns changes its value.

Regards Poul

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Apr 2, 2015 10:38 AM
(6468 views)

This is a great question, PoulRavn, I need to know how to do this as well.