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

id name salary

1 ash   1500

2 ani     *

3 ayu  2000

4 shw   *

5 ami  1200

6 su    *

 

in the above question I  want to replace * with just previous value. what would be the syntax in sas?

e.g In 2nd observation * is replaced by 1500 and in 4th observation * is replaced by 2000 and so on.

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

@ashkum wrote:

salary is nuemric here


Then just edit RW9's code accordingly: Delete (and forget) $200, use ifn in place of ifc and replace "*" by . (the period denotes a numeric missing value) or whatever numeric value was displayed as an asterisk (assuming it was always the same value).

 

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Something like:

data want (drop=lst);
  set have;
  retain lst $200;
  lst=ifc(salary ne "*",salary,lst);
  salary=ifc(salary="*",lst,salary);
run;

Note not tested, I assume salary is character as * is not numeric, post test data in the form of a datastep in future.

ashkum
Calcite | Level 5

salary is nuemric here

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Numeric variables cannot hold the symbol *, therefore either the variable is character or you have changed the missing option.  Either way, this is why we always ask for test data in the form of a datastep to avoid these needless backwards and forwards guessing your data.

FreelanceReinh
Jade | Level 19

@ashkum wrote:

salary is nuemric here


Then just edit RW9's code accordingly: Delete (and forget) $200, use ifn in place of ifc and replace "*" by . (the period denotes a numeric missing value) or whatever numeric value was displayed as an asterisk (assuming it was always the same value).

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1462 views
  • 0 likes
  • 3 in conversation