BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Slash
Quartz | Level 8
Hi, guys!
   
     I got a problem, find the reason, but do not know how to fix it. Here it is:
The sas data is read by using IMPORT procedure. Here is the data look like:

QQ截图20140513104222.png

Notice that the last variable GPRS_FLUX is character. So I want to convert it to numeric. I use these code:

data work.test;

  set data.sas_info_20140512173730(rename=(gprs_flux=tp_0));

  gprs_flux=input(tp_0,best12.);

  drop tp_:;

run;

Unfortunately, the log told me that the convertion is failed!!! Here is the Log:

QQ图片20140513105137.jpg

It said the argument of the INPUT function is invalid at row 20, col 12. I really cannot find which is invalid. It tortured me half an hour.


Finally I export the data to TXT file, I realize the problem. Here is the exported text file:

QQ图片20140513110258.jpg

It got a quotation marks! How does this happen???? Why I can't see it in EG????

So the problem is caused by the quotation marks, so how to convert it to numeric?

Note: the data is in the remote SAS server,  so don't tell me to read the data again. Because there are lots of data is automatically read, and the data's column is not same at each time, so must use the IMPORT procedure.

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Please try the below code  

data work.test;    

set data.sas_info_20140512173730(rename=(gprs_flux=tp_0));    

gprs_flux=input(compress(tp_0,,'kw'),best12.);     

drop tp_:;  

run;

I used the compress function to remove the non printable characters. There are some hidden non printable characters in the variable imported. Due to which the character data is not converted to numeric.

Note: KW in compress stands for keep writable.

Hope this helps.

Thanks,

Jag

Thanks,
Jag

View solution in original post

4 REPLIES 4
stat_sas
Ammonite | Level 13

Not sure about the data type when you imported but you can use dequote to get rid of quotation marks.

data work.test;

  set data.sas_info_20140512173730(rename=(gprs_flux=tp_0));

  gprs_flux=input(dequote(tp_0),best12.);

  drop tp_:;

run;

Slash
Quartz | Level 8

Thanks! It's my fault, not the quotation marks' problem. The data contain a RETURN Key, that's the key.

I just didn't find out, when I use notepad++ open the exported data, it looks like this, different from the notepad.

QQ截图20140513132742.png

And I use $hex. format to put the data, and there is a RETURN key, check out my another comment.

Thank you all the same!

Jagadishkatam
Amethyst | Level 16

Please try the below code  

data work.test;    

set data.sas_info_20140512173730(rename=(gprs_flux=tp_0));    

gprs_flux=input(compress(tp_0,,'kw'),best12.);     

drop tp_:;  

run;

I used the compress function to remove the non printable characters. There are some hidden non printable characters in the variable imported. Due to which the character data is not converted to numeric.

Note: KW in compress stands for keep writable.

Hope this helps.

Thanks,

Jag

Thanks,
Jag
Slash
Quartz | Level 8

Thanks very much! That can fix this problem.Smiley Wink

And I learn the another usage of compress function. Thanks again!

And I also find the character which cause the problem, it's not the quotation marks. It's the RETURN key.

I use $hex. format to put the variable's value, find the '0d'x character. Here it is:

data test;

  set data.bqc_to_sas_info_20140512173730(obs=10);

  tp=put(gprs_flux,$hex.);

run;

QQ截图20140513131738.png

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1054 views
  • 4 likes
  • 3 in conversation