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

Hi,

 

I was wondering if someone can help me with this. I've been stuck on this for a while now and need an answer fast as I have an assignment to hand in.

 

I'm not quite sure how to write SAS code for the following problem: "If the first character of s_cmstdtc is "U", leave the numeric value missing."

 

Any help will be appreciated! Thank you!!

1 ACCEPTED SOLUTION

Accepted Solutions
kiranv_
Rhodochrosite | Level 12

use char or substr function 

data class;
set sashelp.class;
if upcase(char(name,1))="A" then new_var = .;
else new_var = 0;
if upcase(substr(name,1,1))="A" then new_var1 = .;
else new_var1 = 0;
run;

View solution in original post

3 REPLIES 3
kiranv_
Rhodochrosite | Level 12

use char or substr function 

data class;
set sashelp.class;
if upcase(char(name,1))="A" then new_var = .;
else new_var = 0;
if upcase(substr(name,1,1))="A" then new_var1 = .;
else new_var1 = 0;
run;
Patelbb
Fluorite | Level 6

Thank you!!!

novinosrin
Tourmaline | Level 20

@Patelbb While it is perfectly fine to seek urgent help, you could also post better samples of what you have and want rather than a plain sentence leading to some ambiguity where it's a variable operand/constant operand and what and where to assign missing or leave missing as per your words

 

Anyways, first function is very convenient for you to use rather than char or substr if i understand your requirement

 

if first(strip(var))='U' then do whatever you want

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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