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

I have an interesting case where all values of -5 in my dataset should be set to missing. I don't want to have to do this for every variable separately, is there way to recode all instances of -5 in the dataset as missing or .S? Any help would be greatly appreciated. This came about from the way a QDS interview was programmed for skipped questions. Thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

At this point you may want something like:

data want;

     set have;

     array n _numeric-;

     do _i_=1 to dim(n);

          if n[_i_] = -5 then n[_i_] = .;

     end;

run;

View solution in original post

4 REPLIES 4
ballardw
Super User

At this point you may want something like:

data want;

     set have;

     array n _numeric-;

     do _i_=1 to dim(n);

          if n[_i_] = -5 then n[_i_] = .;

     end;

run;

rfarmenta
Obsidian | Level 7

Do I have to assign the array for all of my variables? I am a little confused by your code, whar does the n_numeric refer to? I was able to get the code to run but it did not do anything to the -5. Thank you for your reply!

Quentin
Super User

looks like just a typo in ballardw's suggestion.

It should be:

array n _numeric_ ;

n is the name of the array.

_numeric_ is a special name meaning "all numeric variables".

I think your initial thought to use .S intead of . also has merit.

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
rfarmenta
Obsidian | Level 7

I just noticed the typo and got it to run, I used .S and everything seemed to work correctly. Thank you all for your suggestions.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 4 replies
  • 629 views
  • 3 likes
  • 3 in conversation