SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Range as a variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Range as a variable

Hi, i have one column named 9-24 . Is there a way to use is in a "keep" statement? I'm new to SAS and all the ways I tried failed as it's considered a range from 9 to 24.


Accepted Solutions
Solution
‎06-28-2014 05:53 PM
Super User
Posts: 17,898

Re: Range as a variable

Keep '19-24'n

Wrap each variable you want to keep in a single quote followed by an n.

'VARIABLE'n

View solution in original post


All Replies
Trusted Advisor
Posts: 1,204

Re: Range as a variable

Are you trying to import variable from other source into SAS? Can you please show log?

Occasional Contributor
Posts: 10

Re: Range as a variable

Just merging 2 datasets.

Trusted Advisor
Posts: 1,204

Re: Range as a variable

So variable name is 9-24 and this is in SAS dataset?

Occasional Contributor
Posts: 10

Re: Range as a variable

yes

Trusted Advisor
Posts: 1,204

Re: Range as a variable

What is the error message? Variable name does not conform to SAS naming conventions.

Occasional Contributor
Posts: 10

Re: Range as a variable

ERROR 214-322: Variable name 19 is not valid

It was imported from excell.

Respected Advisor
Posts: 4,654

Re: Range as a variable

"9-24" is the label of the imported variable. It is not a valid SAS variable name, so it was replaced with "__24" (two underscores). You can use (keep=__24).

PG

PG
Trusted Advisor
Posts: 1,204

Re: Range as a variable

If you can change variable name in excel then do that. SAS variable name must begin with a letter (A-Z, either uppercase or lowercase) or an underscore (_).

Occasional Contributor
Posts: 10

Re: Range as a variable

Didn't work. I'm using" options validvarname=any" if that helps

Super User
Posts: 17,898

Re: Range as a variable

Try 

KEEP '9'n-'24'n.

Occasional Contributor
Posts: 10

Re: Range as a variable

ERROR: Not all variables from the list '9'n-'24'n have been found

Super User
Posts: 17,898

Re: Range as a variable

Try double dash instead of single dash. If that doesn't work, please post the results from proc contents on your dataset.

proc contents data=have; run;

Occasional Contributor
Posts: 10

Re: Range as a variable

Bez tytułu.bmpBez tytułu2.bmp

Solution
‎06-28-2014 05:53 PM
Super User
Posts: 17,898

Re: Range as a variable

Keep '19-24'n

Wrap each variable you want to keep in a single quote followed by an n.

'VARIABLE'n

☑ This topic is solved.

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

Discussion stats
  • 15 replies
  • 594 views
  • 0 likes
  • 5 in conversation