BookmarkSubscribeRSS Feed
arpit
Calcite | Level 5
I have a row data like

THE NAME OF COUNTRY IS INDIA
THE NAME OF COUNTRY IS AMERICA
THE NAME OF COUNTRY IS LONDON
THE NAME OF COUNTRY IS CANADA

I have to make a data set which is like

name
INDIA
AMERICA
LONDON
CANADA

Please help me Message was edited by: arpit
6 REPLIES 6
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Use the SCAN function with -1 as the second argument to select the last word.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

scan function site:sas.com
arpit
Calcite | Level 5
The .csv file contain below data

THE NAME OF COUNTRY IS INDIA
THE NAME OF COUNTRY IS AMERICA
THE NAME OF COUNTRY IS LONDON
THE NAME OF COUNTRY IS CANADA



I have to create a dataset like

name
INDIA
AMERICA
LONDON
CANADA



can u explain me
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
From the data presented, it does not appear to be a "CSV" formatted file. What is unclear is whether the entire data-string is contained in one cell or multiple?

You can use SAS PROC IMPORT to read the external file -- this process will create a SAS database member/file for you. Then you can use a SAS DATA step with a SET to read your imported SAS file, and use a SAS character variable assignment statement. Code a LENGTH or ATTRIB statement to declare the new variable that will contain the sub-string value, and make use of the SCAN function, as shown below:

data _null_;
oldvar = "A B C D XXXXXXX';
length newvar $20;
newvar = scan(oldvar,-1,' ');
putlog _all_;
run;

Suggest using the Google searches below and review SAS-hosted documentation and supplemental technical / conference reference material.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

proc import csv introduction site:sas.com

data step programming introduction site:sas.com

data step scan function site:sas.com
arpit
Calcite | Level 5
Thanks for your kind information

But how it use to make a data step like

INDIA
AMERICA
LONDON
CANADA Message was edited by: arpit
FloydNevseta
Pyrite | Level 9
There's a couple of ways you can do it. I'm using instream data in my code, but the data could be in a text file.

This is the method that Scott referred to in his post:

data method1;
input line $40.;
length country $8;
country = scan( line, -1 );
drop line;
datalines;
THE NAME OF COUNTRY IS INDIA
THE NAME OF COUNTRY IS AMERICA
THE NAME OF COUNTRY IS LONDON
THE NAME OF COUNTRY IS CANADA
;
run;


Another alternative:

data method2;
input @'THE NAME OF COUNTRY IS ' country $;
datalines;
THE NAME OF COUNTRY IS INDIA
THE NAME OF COUNTRY IS AMERICA
THE NAME OF COUNTRY IS LONDON
THE NAME OF COUNTRY IS CANADA
;
run;
Ksharp
Super User
Hi:
How about it:
[pre]
filename csv 'c:\test.csv';
data want;
infile csv length=len;
input whole $varying200. len;
country=scan(whole,-1);
drop whole;
run;
[/pre]



Ksharp

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1242 views
  • 0 likes
  • 4 in conversation