BookmarkSubscribeRSS Feed
twildone
Pyrite | Level 9

 

Hi, Is there a way to ensure that missing entries for character fields have blanks and missing entries for numeric fields have the decimal point when importing data and when working datsets. Thanks.

 

data ListFinal;
   set ListFinal;
   array NumVar _numeric_;
   do over NumVar;
      if NumVar < 0 and NumVar not in (.) then NumVar=.;
   end;
run;

data ListFinal;
   set ListFinal;
   array CharVar _character_;
   do over CharVar;
      if CharVar in ('.',''," ",' ') then CharVar='';
   end;
run;
3 REPLIES 3
yabwon
Onyx | Level 15

Hi @twildone ,

 

Do you mean situation where you have data already in sas dataset, or when you are reading from a text file?

Btw. in case of text variables: 

" " = "" = '' = ' '

All the best;

Bart

 

PS you can do your code in 1 datastep (one data read/write):

data ListFinal;
   set ListFinal;
   array NumVar _numeric_;
   array CharVar _character_;

   do over NumVar;
      if not (NumVar > .z) then NumVar=.;
   end;
   do over CharVar;
      if CharVar in ('.',' ') then CharVar='';
   end;
   /* what about this case: '  .' ?*/
run;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



twildone
Pyrite | Level 9

Hi...when I am reading in from a text file....thanks

yabwon
Onyx | Level 15
Hi, do you have any small example?
Bart
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



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!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 543 views
  • 0 likes
  • 2 in conversation