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-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
  • 6 replies
  • 894 views
  • 0 likes
  • 4 in conversation