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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 659 views
  • 0 likes
  • 2 in conversation