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



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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 713 views
  • 0 likes
  • 2 in conversation