BookmarkSubscribeRSS Feed
maryam_h_research
Calcite | Level 5

Need help with doing the following... dont know where to start or how to do it! :smileyconfused:

seems pretty hard to do!

ts1.pngts2.png

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

Hi,

data want;

     set have;

     retain artname2 artedit_id;

     if substr(art_name,1,1) ne "2" then do;

          artname2=art_name;

          artedit_id=art_name;

     end;

Run;

maryam_h_research
Calcite | Level 5

They there RW9,

this was very helpful, and much easier than I thought.

just 2 questions;

1. can you explain to me : if substr(art_name,1,1) ne "2" then do;

2. in artedit_id=art_name; how does one concatenate 2 different data types - a character and number, does a copy of version need to be created as a character and then concatenated with art_name_2?

thanking you & regards,

m.

maryam_h_research
Calcite | Level 5

hello RW9,

following on from my post below.

i got this done.

i did it over a number of data steps, but its okay i guess, it got the job done Smiley Wink

data test;

     set sample_wiki7;

     retain artname2 artedit_id;

     if substr(art_name,1,1) ne "2" then do;

          artname2=art_name;

     end;

run;

data test2;

set test;

  version2 = put(version, 3.) ;

run;

data test3;

set test2;

  ID = catx('', artname2,version2) ;

run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

For your questions:

1)  It basically means if the first character of art_name is a 2, so it s not one we hold over the next rows, then retain that value.

2)  To concatenate different types, there is several options.  The main one would be put (and input) which convert data.  So string || put(number,best.)  will transform the number into a string defined by the format - best. in this case) - and then concatenate that string to the other.

Glad you got your job done, you can wrap up the code lines as:

data test;

     set sample_wiki7;

     retain artname2 artedit_id;

     if substr(art_name,1,1) ne "2" then do;

          artname2=art_name;

     end;

     version2 = put(version, 3.) ;

     ID = catx('', artname2,version2) ;

run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 491 views
  • 1 like
  • 2 in conversation