Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying formats to compued vars #175

Open
j-honnacker opened this issue Mar 4, 2024 · 1 comment
Open

Applying formats to compued vars #175

j-honnacker opened this issue Mar 4, 2024 · 1 comment

Comments

@j-honnacker
Copy link

j-honnacker commented Mar 4, 2024

Hi,

it would be very helpful if formats could be applied to computed variables - especially when working with date/time columns. The functionality seems to be there, but it's breaking the table reference.

Example: Based on a datetime column I can successfully add a time column that holds the hour of the datetime column.

# example table
conn.datastep.runCode(
	code =
	'''data test;
		format datetime e8601dt19.;
		datetime = dhms("03mar2024"d, 9, 50, 0);
		price    = 101.4;
		output;
		datetime = dhms("03mar2024"d, 10, 20, 0);
		price    = 102.5;
		output;
	run;''',
	single = 'yes'
)
tbl = conn.CASTable('test')

# add column containing the hour of the datetime column
tbl['time'] = tbl['datetime'].dt.hour*60*60

# apply time format to new column
tbl.computedvars = [{'name':'time', 'format':'time8.'}]

# check if time format was applied
tbl.columnInfo()

image

# check if time format works
tbl.head()

image

Unfortunately, after applying the format as shown above, I can't execute any operations on the table anymore:

tbl[tbl['price']>=102].head()

image

@bkemper24
Copy link
Contributor

I will look into this. Thanks for providing the example code for the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants