Subscribe Bookmark RSS Feed

How to joining two columns with JSL

pomemelom

New Contributor

Joined:

Jan 31, 2017

Hi I am new to JSL, and I got stuck in a seemlily easy task.

Say I have two columns A and B, and have some missing values.

I'd like to create a new column to be the join of column A and B.

As shown in example below. 

 

Thanks!

 

Snap278.bmp

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution

Here is a couple of simple examples

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

dt << New Column( "New Column", character, formula( name || sex ) );

// or 
dt << New Column( "Second New Column", character );
For( i = 1, i <= N Rows( dt ), i++,
	dt:Second New Column[i] = dt:name[i] || dt:sex[i]
)are 
Jim
4 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

Solution

Here is a couple of simple examples

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

dt << New Column( "New Column", character, formula( name || sex ) );

// or 
dt << New Column( "Second New Column", character );
For( i = 1, i <= N Rows( dt ), i++,
	dt:Second New Column[i] = dt:name[i] || dt:sex[i]
)are 
Jim
meperry

New Contributor

Joined:

Aug 23, 2017

I am having the same issue, but the code provided here does not work.  I am dealing with continuous data, perhaps that is the problem? Or is it that my variable names are longer than SAS allows, so using them in JSL creates an error?

 

My data subset looks like such:

 

StdURM1BLFIStdURM1BLMI 
.. 
-0.0316815. 
.-0.33056098 

 and I would like the third column to contain the data from the other two (or keep a missing data value as necessary), e.g.:

 

StdURM1BLFIStdURM1BLMIZscore
...
-0.0316815.-0.0316815
.-0.33056098-0.33056098

 

Thank you!

ian_jmp

Staff

Joined:

Jun 23, 2011

So long as only one of the two columns has a non missing value, you could try 'Sum()'. Look at the formula in the table below:

New Table( "Both",
	Add Rows( 4 ),
	New Column( "a",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [., 1, ., 3] )
	),
	New Column( "b",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [., ., 2, 4] )
	),
	New Column( "c",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula( Sum( :a, :b ) )
	)
) e

 

meperry

New Contributor

Joined:

Aug 23, 2017

The sum function works!  Thank you!