BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GN0001
Barite | Level 11

Data mydate;

Input health plan$ sub health plan$ diag code 1$;

Datalines;

Marina hills county Misson plan 234;

;

Run;

What should I do that SAS ignores spaces on the headers?

What should I do that SAS sees Marian hills county is a value for health plan?

What should I do that SAS sees Mission is a value for sub health plan?

Respectfully,

Blue Blue

 

 

Blue Blue
1 ACCEPTED SOLUTION

Accepted Solutions
LeonidBatkhan
Lapis Lazuli | Level 10

Hi GN0001,

You can do this using the following code:

options validvarname=any;

data mydate;
   infile datalines dlm=',';
   length 'health plan'n $40 'sub health plan'n $30 'diag code'n $10;
   input 'health plan'n 'sub health plan'n 'diag code'n;
   datalines;
Marina hills county, Misson plan, 234
;

Hope this helps.

View solution in original post

6 REPLIES 6
LeonidBatkhan
Lapis Lazuli | Level 10

Hi GN0001,

You can do this using the following code:

options validvarname=any;

data mydate;
   infile datalines dlm=',';
   length 'health plan'n $40 'sub health plan'n $30 'diag code'n $10;
   input 'health plan'n 'sub health plan'n 'diag code'n;
   datalines;
Marina hills county, Misson plan, 234
;

Hope this helps.

GN0001
Barite | Level 11
This is very nice!
I have to test it though.
Thanks,
Blue Blue
Blue Blue
ballardw
Super User

Best practice would be copy a few lines, 5 to 10 of so, from the text file you are attempting to read, if that is the case and paste them into a text box opened on the forum with the </> icon just above the message window. The text box is pretty critical because the main message windows on this forum will reformat text, typically reducing white space (multiple spaces for example) which means that the example we see could very well not be the text you posted.

 

Spaces in the headers? What headers? I don't see any headers. Headers are typically the first line of a file.

 

Variable names by default cannot contain spaces or characters other than letters, digits and the underscore character _. If you want to use such non-standard names you must have the SAS system option VALIDVARNAME=ANY set.

Then you can create and use the extremely ugly name literals such as "health plan"n or "sub health plan"n. Every time you use these variables you must use a quote around the whole name immediately followed by the n to tell SAS the thing is indeed supposed to be a SAS variable name. 

 

Easiest to see and understand is the delimited text such as @LeonidBatkhan shows. If you have a file to read that does not have a delimiter then you really need to provide an example so we have a chance of providing something else that doesn't involve manually typing a bunch of delimiter characters.

GN0001
Barite | Level 11

Sometime, the worse scenario case comes to my mind and I get frozen and I need to find a solution for it.

I will let you know if I have it in real world.

I created a data set to test something and I came across this problem.

I will put code in a box next time for sure.

what does 'n do? 

Please advise me.

Regards,

Blue Blue 

Blue Blue
ballardw
Super User

@GN0001 wrote:

Sometime, the worse scenario case comes to my mind and I get frozen and I need to find a solution for it.

I will let you know if I have it in real world.

I created a data set to test something and I came across this problem.

what does 'n do? 

Please advise me.

Regards,

Blue Blue 


The quotes and the n together create a name literal as I said.

 

SAS has a number of special constructs for designating literal values of one type or another that have this quote and letter.  '01JAN2021'd  date literal, '14:23:16't  a time literal, '01JAN2021:14:23:16'dt a datetime literal value.

The 'obnoxious text for var'n is a name literal that can be used as a variable when Validvarname=any is in effect.

 

The name literal was apparently added to deal with external database connections to data sources that allow other characters and spaces in their variable names so you could write code without having to match a SAS variable name to a differently spelled Database variable (though SAS is still limited to 32 characters).

 

As for reading the data READ the documentation for the INPUT statement. All of it. There are different types of input: list, delimited,formatted, fixed column and named. They all behave differently and can, with some limitations, be mixed in a single input statement. Also there are the options for dealing with columns, finding specific positions to start reading other than delmiters or specific columns. There are multiple ways to read from more than one line for a single observation. There are ways to read one line into multiple observations. There are ways to read part of line of text, test values and decide if you are done with that specific line and are ready to advance to the next.

 

The documentation has examples of a fair number of different cases. Describing any significant number would be rewriting the documentation.

LeonidBatkhan
Lapis Lazuli | Level 10

This is SAS name literal 'some text string'n - n here indicates that text string in quotes is a variable name.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 3602 views
  • 2 likes
  • 3 in conversation